Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int findPathInMaze(int **, int, int, int, int);
  6. int fibRecursive(int);
  7.  
  8. int main(){
  9.  
  10.  
  11. }
  12. //Fibonacci number
  13. int fibRecursive(int num){
  14.     if(num == 1){
  15.         return 1;
  16.     }
  17.     if(num == 0){
  18.         return 0;
  19.     }
  20.     else{
  21.         return fibRecursive(num - 1) + fibRecursive(num - 2);
  22.     }
  23. }
  24.  
  25.  
  26. //Finding a path in a maze recursively
  27. int findPathInMaze(int **arr, int sizeOfArray, int exit, int x, int y){
  28.     /*
  29.     The walls are represented with 1's, the empty paths are represented with 0's,
  30.     the exit is represented with 2 and the marked path is represented with 3's.
  31.     */
  32.     if(arr[x][y] == exit){
  33.         return 4;
  34.     }
  35.     else{
  36.         if(arr[x][y+1] == 0){//If right is empty, move right and mark the current location
  37.             findPathInMaze(arr, sizeOfArray, exit, x, y+1);
  38.             arr[x][y] = 3;
  39.  
  40.         }
  41.         if(arr[x][y-1] == 0){//If left is empty, move left and mark the current location
  42.             findPathInMaze(arr, sizeOfArray, exit, x, y-1);
  43.             arr[x][y] = 3;
  44.         }
  45.         if(arr[x+1][y] == 0){//If down is empty, move down and mark the current location
  46.             findPathInMaze(arr, sizeOfArray, exit, x+1, y);
  47.             arr[x][y] = 3;
  48.  
  49.         }
  50.         if(arr[x-1][y] == 0){//If top is empty, move up and mark the current location
  51.             findPathInMaze(arr, sizeOfArray, exit, x-1, y);
  52.             arr[x][y] = 3;
  53.         }
  54.  
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement