• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest Nov 9th, 2019 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. void findPath(char maze[HEIGHT][WIDTH], Node *p)
2. {
3.      int nx = p->x;
4.      int ny = p->y;
5.      maze[nx][ny] = '2';
6.      if (maze[nx-1][ny] == '0')
7.      {
8.          Node *node = malloc(sizeof(Node));
9.          node->x = nx-1;
10.          node->y = ny;
11.          node->up = NULL;
12.          node->down = NULL:
13.          node->left = NULL;
14.          node->right = NULL:
15.
16.          p->up = node;
17.          findPath(maze, node);
18.      }
19.      if (maze[nx+1][ny] == '0')
20.      {
21.          Node *node = malloc(sizeof(Node));
22.          node->x = nx+1;
23.          node->y = ny;
24.          node->up = NULL;
25.          node->down = NULL:
26.          node->left = NULL;
27.          node->right = NULL:
28.
29.          p->down = node;
30.          findPath(maze, node);
31.      }
32.      if(maze[nx][ny-1] == '0')
33.      {
34.          Node *node = malloc(sizeof(Node));
35.          node->x = nx;
36.          node->y = ny-1;
37.          node->up = NULL;
38.          node->down = NULL:
39.          node->left = NULL;
40.          node->right = NULL:
41.
42.          p->left = node;
43.          findPath(maze, node);
44.      }
45.      if(maze[nx][ny+1] == '0')
46.      {
47.          Node *node = malloc(sizeof(Node));
48.          node->x = nx;
49.          node->y = ny+1;
50.          node->up = NULL;
51.          node->down = NULL:
52.          node->left = NULL;
53.          node->right = NULL:
54.
55.          p->right = node;
56.          findPath(maze, node);
57.      }
58.      return;
59.
60.          /*maze[x-1][y] = '2';
61.          Node* node = malloc(sizeof(Node));
62.          node->x = x-1;
63.          node->y = y;
64.          p->up = node;
65.          findPath(maze, x-1, y, node);*/
66.
67.
68. }
69.
70. int main()
71. {
72.     Node* startNode = malloc(sizeof(Node));
73.     startNode->x = sx;
74.     startNode->y = sy;
75.     startNode->up = NULL;
76.     startNode->down = NULL:
77.     startNode->left = NULL;
78.     startNode->right = NULL:
79.     findPath(maze, startNode);
80.
81.
82. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top