Advertisement
Guest User

Untitled

a guest
Nov 14th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 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. bool found = false;
  8.  
  9. if((maze_position->right() == nullptr) && (maze_position->left() == nullptr)){ found = false; }
  10.  
  11. if( maze_position->is_finish() ){
  12. found = true;
  13. }
  14.  
  15. else{
  16.  
  17.  
  18. if( (maze_position->left() != nullptr) && (!found) ){ ///I had added comment so that it only looks when it isnt found
  19. print_path_through_maze(maze_position->left());
  20. if(print_path_through_maze(maze_position->left())){ std::cout << '0'; } //and i wanted this to check after the recursive call, but whn I add it
  21. //the code never reaches this points.
  22. //std::cout << '0';
  23.  
  24. } //There are two mazes, 0 and 1, that you can change in main
  25.  
  26. if( (maze_position->right() != nullptr) && (!found) ){
  27. print_path_through_maze(maze_position->right());
  28. if(print_path_through_maze(maze_position->right())){ std::cout << '1'; }
  29.  
  30. // std::cout << '1';
  31. }
  32. }
  33.  
  34. return found;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement