C로 구현한 미로찾기
본 자료는 미리보기를 지원하지 않습니다.
닫기
  • 1
  • 2
  • 3
해당 자료는 1페이지 까지만 미리보기를 제공합니다.
1페이지 이후부터 다운로드 후 확인할 수 있습니다.

소개글

C로 구현한 미로찾기에 대한 보고서 자료입니다.

목차

없음

본문내용

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;
}
}

키워드

미로,   미로찾기,   C
  • 가격700
  • 페이지수3페이지
  • 등록일2010.06.01
  • 저작시기2004.05
  • 파일형식압축파일(zip)
  • 자료번호#616279
본 자료는 최근 2주간 다운받은 회원이 없습니다.
청소해
다운로드 장바구니