미안하다 이거 질문할려고 어그로 끌었다...깃헙갤 답변수준ㄹㅇ실화냐??진짜 업계1인자들의답변이다...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110

int neighbor(element next, element here) {
StackType s;
StackType s2;
while (maze[here.x][here.y] != maze[next.x - 1][next.y] || maze[here.x][here.y] != maze[next.x + 1][next.y] || maze[here.x][here.y] != maze[next.x][next.y - 1] || maze[here.x][here.y] != maze[next.x][next.y + 1]) {
maze[here.x][here.y] = PATH;
here = pop(&s2);
}
}
int main(void)
{
int x, y;
char buf[10];
element here;
element next;
StackType s;
StackType s2;
init_stack(&s);
init_stack(&s2);
init_maze(&entry);
here = entry; // 구조체 지정 (x, y) 값 복사
while (maze[here.x][here.y] != END) {
push_loc(&s2, here.x, here.y);
x = here.x;
y = here.y;
maze[x][y] = VISITED;
gets_s(buf, 10); // 엔터 쳐야 넘어가게 잠깐 멈춤 기능
maze_print(maze); // 현재 미로 상태 출력
push_loc(&s, x - 1, y); // 상
push_loc(&s, x + 1, y); // 하
push_loc(&s, x, y - 1); // 좌
push_loc(&s, x, y + 1); // 우.. 갈수 있는 곳을 모두 push
if (is_empty(&s)) { // 더이상 갈곳이 없으면 길이 없다는 뜻
printf("실패 ");
return 1;
}
next = pop(&s);
int neighbor(element next, element here);
here = next;
}
printf("성공 ");
return 0;
}
cs

코드에서 필요한 부분만 잘라서 올리라고 해서 이렇게 했는데 전체 필요하면 다시 올리겟읍니다,,,,,

c언어 스택으로 미로찾기하는 과제입니다,,,,


ex)

입력:

6


001011

101001

001100

100000

001110

10011x



출력:


6


##1011

1#1001

.#1100

1#####

00111#

10011G


이렇게 [0][0]에서 시작해서 x에 도달할때까지 지나온길을 #, 들렸다가 막다른길이라서 되돌아온길을 '.'으로 표시하는 코드입니다.

저같은 경우에는 neighbor를 'here'가 'next'의 인접한 칸이 될때까지 'here'를 '.'으로 만들고, s2스택을 계속 pop하는 코드를 만들었는데 while지정하는 부분이 잘못되었는지 어디가 잘못되었는지 .으로 안바꾸고



##1011

1#1001

##1100

1#####

00111#

10011G


경로전부를 구분없이 그냥 #으로만 표시합니다.

되도록 main함수는 저기서 안건들고 neighbor만 건드려서 작동하게 만들고 싶은데 답변주시면 감사드리겟읍니다,,,,,