Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool print_path_through_maze(const maze_node* maze_position)
- // Postcondition: Prints the path through the maze, with 0s representing right
- // turns and 1s representing left turns.
- // You may print the path in reverse order (this will be easier).
- // Hint: Use the return boolean to signify that the current path is the correct path.
- {
- bool found = false;
- if((maze_position->right() == nullptr) && (maze_position->left() == nullptr)){ found = false; }
- if( maze_position->is_finish() ){
- found = true;
- }
- else{
- if( (maze_position->left() != nullptr) && (!found) ){ ///I had added comment so that it only looks when it isnt found
- print_path_through_maze(maze_position->left());
- 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
- //the code never reaches this points.
- //std::cout << '0';
- } //There are two mazes, 0 and 1, that you can change in main
- if( (maze_position->right() != nullptr) && (!found) ){
- print_path_through_maze(maze_position->right());
- if(print_path_through_maze(maze_position->right())){ std::cout << '1'; }
- // std::cout << '1';
- }
- }
- return found;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement