Advertisement
ZhenghaoZhu

Untitled

Nov 13th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. bool print_path_through_maze(const maze_node* maze_position)
  2. // Postcondition: Prints the path through the maze, with 0s representing right
  3. // turns and 1s representing left turns.
  4. // You may print the path in reverse order (this will be easier).
  5. // Hint: Use the return boolean to signify that the current path is the correct path.
  6. {
  7.   if(maze_position->is_finish()){
  8.     cout << endl << "true-BREAK ";
  9.     return true;
  10.   }
  11.   if(!(maze_position->is_finish()) && (maze_position->left() == 0) && (maze_position->right() == 0)){
  12.     cout << endl << "false-BREAK ";
  13.     return false;
  14.   }
  15.   if(maze_position->left() != 0){
  16.     cout << "L";
  17.     print_path_through_maze(maze_position->left());
  18.   }
  19.   if(maze_position->right() != 0){
  20.     cout << "R";
  21.     print_path_through_maze(maze_position->right());
  22.   }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement