Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int findPathInMaze(int **, int, int, int, int);
- int fibRecursive(int);
- int main(){
- }
- //Fibonacci number
- int fibRecursive(int num){
- if(num == 1){
- return 1;
- }
- if(num == 0){
- return 0;
- }
- else{
- return fibRecursive(num - 1) + fibRecursive(num - 2);
- }
- }
- //Finding a path in a maze recursively
- int findPathInMaze(int **arr, int sizeOfArray, int exit, int x, int y){
- /*
- The walls are represented with 1's, the empty paths are represented with 0's,
- the exit is represented with 2 and the marked path is represented with 3's.
- */
- if(arr[x][y] == exit){
- return 4;
- }
- else{
- if(arr[x][y+1] == 0){//If right is empty, move right and mark the current location
- findPathInMaze(arr, sizeOfArray, exit, x, y+1);
- arr[x][y] = 3;
- }
- if(arr[x][y-1] == 0){//If left is empty, move left and mark the current location
- findPathInMaze(arr, sizeOfArray, exit, x, y-1);
- arr[x][y] = 3;
- }
- if(arr[x+1][y] == 0){//If down is empty, move down and mark the current location
- findPathInMaze(arr, sizeOfArray, exit, x+1, y);
- arr[x][y] = 3;
- }
- if(arr[x-1][y] == 0){//If top is empty, move up and mark the current location
- findPathInMaze(arr, sizeOfArray, exit, x-1, y);
- arr[x][y] = 3;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement