I'm trying to solve a maze recursively. I wrote the code but I keep getting an infinte loop. I looked online and the code and logic is the same. Can somebody tell me what I'm doing wrong? Thanks
Its a 5x5 maze and here is the maze
xsxxx
x---x
x--xx
e---x
xx-xx
Code:bool solveMaze(int startRow, int startCol, char maze [][5]){ if(maze[startRow][startCol]=='e'){ return true; }//end if if(startRow>4 || startCol>4 || startRow<0 || startCol<0){ return false; }//end if if(maze[startRow][startCol]=='x'){ return false; }//end if if(solveMaze(startRow+1, startCol, maze)){ return true; }//end if if(solveMaze(startRow, startCol+1, maze)){ return true; }//end if(solveMaze(startRow-1, startCol, maze)){ return true; }//end if if(solveMaze(startRow, startCol-1, maze)){ return true; }//end if return false; }//end solveMaze



LinkBack URL
About LinkBacks


