this code doesn’t give output
RAT IN A MAZE in backtracking algo
void printInaMaze(char maze[4][4], int sol[4][4], int sr, int sc, int er, int ec)
{
if (sr > er and sc > ec)
{
return;
}
if (sr == er and sc == ec)
{
sol[sr][sc] = 1;
for (int i = 0; i <= er; i++)
{
for (int j = 0; j <= ec; j++)
{
cout << sol[i][j]<<" ";
}
cout << endl;
}
return;
}
if (maze[sr][sc] == 'X')
{
return;
}
if(maze[sr][sc] == '0'){
sol[sr][sc] = 1;
printInaMaze(maze, sol, sr + 1, sc, er, ec);
printInaMaze(maze, sol, sr, sc + 1, er, ec);
sol[sr][sc] = 0;
}
return;
}
use this is more efficient without using extra space
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.