목차
없음
본문내용
include
#include
#define MAX_STACK_SIZE 60
#define TRUE 1
#define FALSE 0
#define SIZE 12
typedef struct{
int row;
int col;
int dir;
} element;
element stack[MAX_STACK_SIZE];
element position;
typedef struct{
int vert;
int horiz;
} offsets;
offsets move[8] = {
{-1, 0},
{-1, 1},
{ 0, 1},
{ 1, 1},
{ 1, 0},
{ 1, -1},
{ 0, -1},
{-1, -1}
};
void add(int *top, element position);
element delete(int *top);
void stack_full(void);
void stack_empty(void);
main()
{
int maze[SIZE][SIZE]={{1,1,1,1,1,1,1,1,1,1,1,1},
{1,0,1,1,1,1,0,0,1,1,1,1},
{1,0,1,1,1,0,1,0,1,1,1,1},
{1,1,0,0,0,1,1,1,0,1,1,1},
{1,1,1,1,1,1,0,0,1,1,1,1},
{1,1,1,0,0,0,1,1,1,1,1,1},
{1,1,0,1,1,1,1,0,0,1,1,1},
{1,0,1,1,1,1,0,1,1,0,1,1},
{1,1,0,0,1,1,0,1,0,1,1,1},
{1,1,1,1,0,0,1,1,0,0,1,1},
{1,1,1,1,1,1,1,1,1,1,0,1},
{1,1,1,1,1,1,1,1,1,1,1,1}};
int i, row, col, next_row, next_col, dir=0,
found=FALSE, EX_ROW=10, EX_COL=10;
int top, x, y;
int mark[SIZE][SIZE]={{1,1,1,1,1,1,1,1,1,1,1,1},
{1,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1,1,1,1}};
mark[1][1]=1; top=0;
stack[0].row=1; stack[0].col=1; stack[0].dir=1;
while ((top>-1) && (!found)){
position=delete(&top);
row=position.row;
col=position.col;
dir=position.dir;
while ((dir<8) && (!found)){
next_row=row+move[dir].vert;
next_col=col+move[dir].horiz;
if ((next_row == EX_ROW) && (next_col == EX_COL))
found=TRUE;
else if ((!maze[next_row][next_col]) &&
(!mark[next_row][next_col])){
mark[next_row][next_col] = 1;
position.row=row;
position.col=col;
position.dir=++dir;
add(&top, position);
row=next_row;
col=next_col;
dir=0;
}
else ++dir;
}
}
#include
#define MAX_STACK_SIZE 60
#define TRUE 1
#define FALSE 0
#define SIZE 12
typedef struct{
int row;
int col;
int dir;
} element;
element stack[MAX_STACK_SIZE];
element position;
typedef struct{
int vert;
int horiz;
} offsets;
offsets move[8] = {
{-1, 0},
{-1, 1},
{ 0, 1},
{ 1, 1},
{ 1, 0},
{ 1, -1},
{ 0, -1},
{-1, -1}
};
void add(int *top, element position);
element delete(int *top);
void stack_full(void);
void stack_empty(void);
main()
{
int maze[SIZE][SIZE]={{1,1,1,1,1,1,1,1,1,1,1,1},
{1,0,1,1,1,1,0,0,1,1,1,1},
{1,0,1,1,1,0,1,0,1,1,1,1},
{1,1,0,0,0,1,1,1,0,1,1,1},
{1,1,1,1,1,1,0,0,1,1,1,1},
{1,1,1,0,0,0,1,1,1,1,1,1},
{1,1,0,1,1,1,1,0,0,1,1,1},
{1,0,1,1,1,1,0,1,1,0,1,1},
{1,1,0,0,1,1,0,1,0,1,1,1},
{1,1,1,1,0,0,1,1,0,0,1,1},
{1,1,1,1,1,1,1,1,1,1,0,1},
{1,1,1,1,1,1,1,1,1,1,1,1}};
int i, row, col, next_row, next_col, dir=0,
found=FALSE, EX_ROW=10, EX_COL=10;
int top, x, y;
int mark[SIZE][SIZE]={{1,1,1,1,1,1,1,1,1,1,1,1},
{1,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1,1,1,1}};
mark[1][1]=1; top=0;
stack[0].row=1; stack[0].col=1; stack[0].dir=1;
while ((top>-1) && (!found)){
position=delete(&top);
row=position.row;
col=position.col;
dir=position.dir;
while ((dir<8) && (!found)){
next_row=row+move[dir].vert;
next_col=col+move[dir].horiz;
if ((next_row == EX_ROW) && (next_col == EX_COL))
found=TRUE;
else if ((!maze[next_row][next_col]) &&
(!mark[next_row][next_col])){
mark[next_row][next_col] = 1;
position.row=row;
position.col=col;
position.dir=++dir;
add(&top, position);
row=next_row;
col=next_col;
dir=0;
}
else ++dir;
}
}
소개글