As you move up the stack, the values get updated and never "backtrack" since they dont retain their original values in each level, backtracking is basically walking a tree, if each node does not retain the original value when you update it at each level, every node will have the value of the leaf node , when the leaf node is met, nodes do not remember their original value. Instead you need to pass a new value as you traverse up the stack without updating for each stack to remember what they had when they were called by their parent.
Easiest way is to try,
traverse(int maze[][], int x , int y)
and your subsequent call will look something like
if(north(maze, x , y) == true)
{
maze[y-1][x] = 4;
display(maze);
//temp.y--;
if (traverse(maze, x , y-1) == false)
{
maze[y][x] = 3;
}
}
or you could reset your value back after you return to the current stack,
I havent checked the rest of your code, but this is probably the reason for the code not to backtrack