#include #include #include // ÇÁ·Î±×·¥ 5.3À» ¿©±â¿¡ Æ÷ÇÔ //... #define MAX_STACK_SIZE 100 #define MAZE_SIZE 6 typedef struct { short r; short c; } element; element here={1,0}, entry={1,0}; typedef struct{ element stack[MAX_STACK_SIZE]; int top; } StackType; // ½ºÅà ÃʱâÈ­ ÇÔ¼ö void init(StackType *s) { s->top = -1; } // °ø¹é »óÅ °ËÃâ ÇÔ¼ö int is_empty(StackType *s) { return (s->top == -1); } // Æ÷È­ »óÅ °ËÃâ ÇÔ¼ö int is_full(StackType *s) { return (s->top == (MAX_STACK_SIZE-1)); } // »ðÀÔÇÔ¼ö void push(StackType *s, element item) { if( is_full(s) ) { fprintf(stderr,"½ºÅà Æ÷È­ ¿¡·¯\n"); return; } else s->stack[++(s->top)] = item; } // »èÁ¦ÇÔ¼ö element pop(StackType *s) { if( is_empty(s) ) { fprintf(stderr, "½ºÅà °ø¹é ¿¡·¯\n"); exit(1); } else return s->stack[(s->top)--]; } // ÇÇÅ©ÇÔ¼ö element peek(StackType *s) { if( is_empty(s) ) { fprintf(stderr, "½ºÅà °ø¹é ¿¡·¯\n"); exit(1); } else return s->stack[s->top]; } char maze[MAZE_SIZE][MAZE_SIZE] = { {'1', '1', '1', '1', '1', '1'}, {'e', '0', '1', '0', '0', '1'}, {'1', '0', '0', '0', '1', '1'}, {'1', '0', '1', '0', '1', '1'}, {'1', '0', '1', '0', '0', 'x'}, {'1', '1', '1', '1', '1', '1'}, }; // À§Ä¡¸¦ ½ºÅÿ¡ »ðÀÔ void push_loc(StackType *s, int r, int c) { if( r < 0 || c < 0 ) return; if( maze[r][c] != '1' && maze[r][c] != '.' ){ element tmp; tmp.r = r; tmp.c = c; push(s, tmp); } } void printmaze() { int i,j; for(i=0;is->top;i--) printf("| |\n"); for(i=s->top;i>=0;i--) printf("|(%01d,%01d)|\n", s->stack[i].r, s->stack[i].c); printf("-------\n"); } // void main() { int r,c; StackType s; init(&s); here = entry; while ( maze[here.r][here.c]!='x' ){ r = here.r; c = here.c; maze[r][c] = '.'; push_loc(&s, r-1,c); push_loc(&s, r+1,c); push_loc(&s, r,c-1); push_loc(&s, r,c+1); printmaze(); printStack(&s); getchar(); if( is_empty(&s) ){ printf("½ÇÆÐ\n"); return; } else here = pop(&s); } printf("¼º°ø\n"); }