내 자신의 Matrix 클래스를 개발했습니다. 생성자는 파일에서 행렬을 읽습니다. 매트릭스에는 자유 세포와 "벽"이 있습니다. 또한 생성자는 폭 넓은 첫 번째 검색 (Start_point에서 Finish_Point까지 최단 경로 찾기)의 시작 및 끝 지점을 읽습니다. 여기 헤더의 코드입니다 :클래스 메서드로 인라인 함수
#ifndef __MYMATRIX_H__
#define __MYMATRIX_H__
#include <tchar.h>
#include <iostream>
#include <deque>
//using namespace std;
#define MAX_MATRIX_SIZE 1000
#define FREE_CELL_SIGNIFICATION '0'
#define BALL_SIGNIFICATION 'B'
#define UP_SIGNIFICATION 'U'
#define DOWN_SIGNIFICATION 'D'
#define LEFT_SIGNIFICATION 'L'
#define RIGHT_SIGNIFICATION 'R'
#define START_POINT_SIGNIFICATION 'S'
#define FINISH_POINT_SIGNIFICATION 'F'
typedef std::pair<int,int> Field_Point_Type;
//#define IS_RIGHT_NEIGHBOUR_REACHABLE(Current_Point) (((Current_Point.second+1) <= Column_Count)&&((Matrix_Field[Current_Point.first][Current_Point.second+1]==FREE_CELL_SIGNIFICATION)||(Matrix_Field[Current_Point.first][Current_Point.second+1]==FINISH_POINT_SIGNIFICATION))) ? true : false;
class Matrix {
private:
int Column_Count; //Cols
int Row_Count;//Rows
char** Matrix_Field;
Field_Point_Type Start_Point;
Field_Point_Type Finish_Point;
bool Matrix_Is_Correct;
public:
Matrix(_TCHAR* Input_File_Name);
int Breadth_first_search(unsigned int Start_X,unsigned int Start_Y,unsigned int Finish_X,unsigned int Finish_Y);
~Matrix();
inline int IS_RIGHT_NEIGHBOUR_REACHABLE(Field_Point_Type Current_Point);
};
//MyMatrix.cpp이 파일
//MyMatrix.h 파일
내가 정의하고 싶습니다...
inline int Matrix::IS_RIGHT_NEIGHBOUR_REACHABLE(Field_Point_Type Current_Point)
{
return (((Current_Point.second+1) <= Column_Count)&&((Matrix_Field[Current_Point.first][Current_Point.second+1]==FREE_CELL_SIGNIFICATION)||(Matrix_Field[Current_Point.first][Current_Point.second+1]==FINISH_POINT_SIGNIFICATION))) ? true : false;
}
...
은 무료 이웃 세포이다 알고리즘의 다음 단계.
if (((Current_Point.second+1) <= Column_Count)&&((Matrix_Field[Current_Point.first][Current_Point.second+1]==FREE_CELL_SIGNIFICATION)||(Matrix_Field[Current_Point.first][Current_Point.second+1]==FINISH_POINT_SIGNIFICATION))) {
//Adding of right cell to deque...
...
}
을하지만 추한 외모 : 물론 나는 이것을 위해 같은 코드를 사용할 수 있습니다. 왼쪽, 위, 아래 셀에 대해 이러한 검사를 추가 할 것입니다. 인라인 함수 (예 : inline int IS_RIGHT_NEIGHBOUR_REACHABLE(Field_Point_Type Current_Point);
)를 구현하고 싶습니다.
if (IS_RIGHT_NEIGHBOUR_REACHABLE(Current_Point)) {
//Adding of right cell to deque...
...
}
훨씬 더 좋아 보인다! 그러나 나는 인라인 함수의 정의를 사용하지 않고 우연히 발견했습니다. 좋은 프로그래밍 스타일입니까? 클래스 내에서 간단한 int IS_RIGHT_NEIGHBOUR_REACHABLE(Field_Point_Type Current_Point);
메서드를 개발하는 것이 더 좋습니까? 는 더 나은 수표를두고하는 것입니다 :
if (((Current_Point.second+1) <= Column_Count)&&((Matrix_Field[Current_Point.first][Current_Point.second+1]==FREE_CELL_SIGNIFICATION)||(Matrix_Field[Current_Point.first][Current_Point.second+1]==FINISH_POINT_SIGNIFICATION))) {
//Adding of right cell to deque...
...
}
CPP 파일에 인라인 함수를 구현하지 마십시오 !! – Goz
(OT : [친구들]이나 다른 인사말을 게시하지 마십시오.] (http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be-removed- from-posts), C++을 맨 앞에 놓지 않으면, 가장 높은 태그가 자동적으로 페이지의'title'에 추가됩니다. 거기에 C++을 넣으려면, 제목 문장에 그것을 흐르게하십시오.) – Mat
OK, Mat. 이렇게 돼서 미안하다. –