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
|
struct node
{
char value;
int x, y;
struct node* left;
struct node* right;
struct node* up;
struct node* down;
};
struct node* newnode(int x, int y, char value)
{
struct node* node = (struct node*)
malloc(sizeof(struct node));
node->x = x;
node->y = y;
node->value = value;
node->left = NULL;
node->right = NULL;
node->up = NULL;
node->down = NULL;
return(node);
}
void printPaths(struct node* node)
{
int path[1000];
printPathsRecur(node, path, 0);
}
void printPathsRecur(struct node* node, int path[], int pathLen)
{
if (node==NULL)
return;
/* append this node to the path array */
path[pathLen] = node->value;
pathLen++;
/* it's a leaf, so print the path that led to here */
if (node->left==NULL && node->right==NULL && node->up==NULL && node->down==NULL)
{
printArray(path, pathLen);
}
else
{
/* otherwise try subtrees */
printPathsRecur(node->left, path, pathLen);
printPathsRecur(node->right, path, pathLen);
printPathsRecur(node->up, path, pathLen);
printPathsRecur(node->down, path, pathLen);
}
}
int main()
{
struct mazeStruct maze;
//read a maze and assign to the struct
struct node *root = newnode(maze.x, maze.y, maze.map[maze.x][maze.y]);
}
|