-
Notifications
You must be signed in to change notification settings - Fork 0
/
t.c
56 lines (48 loc) · 1014 Bytes
/
t.c
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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX_ROW 5
#define MAX_COL 5
int maze[MAX_ROW][MAX_COL] = {
0, 1, 0, 0, 0,
0, 1, 0, 1, 0,
0, 0, 0, 0, 0,
0, 1, 1, 1, 0,
0, 0, 0, 1, 0
};
int top = 0;
struct point {
int row, col;
} stack[512];
int push(struct point p)
{
stack[top++] = p;
}
struct point pop(void)
{
return stack[--top];
}
int is_empty(void)
{
return top == 0;
}
struct point predecessor[MAX_ROW][MAX_COL] = {
{{-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}},
{{-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}},
{{-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}},
{{-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}},
{{-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}}
};
int visit(int row, int col, struct point pre)
{
struct point pt = {row, col};
// 已访问
maze[row][col] = 2;
// 前驱
predecessor[row][col] = pre;
// 压栈
push(pt);
}
// 不为空的时候
while (! is_empty()) {
}