### stack overflow.... help...

how to solve the"stack overflow"problem?????

i'm practicing to write a program about "maze"
the following are parts of my code
it have a problem of stack overflow...
i really don't know how to solve it
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889`` `````` void gogo(vector > &maze, int p, int q){ int ways=0, go; srand(time(NULL)); go=rand()%4; maze[p][q]=3; if(maze[p-1][q]==0||maze[p-1][q]>=201){ ways++; } if(maze[p+1][q]==0||maze[p+1][q]>=201){ ways++; } if(maze[p][q-1]==0||maze[p][q-1]>=201){ ways++; } if(maze[p][q+1]==0||maze[p][q+1]>=201){ ways++; } if(ways>=2){ r=p; k=q; } else if(ways<=1){ r=r; k=k; } //system("pause"); ////////////////////////////////// if(go==0&&(maze[p-1][q]==0||maze[p-1][q]>=201)){ maze[p-1][q]==3; printrealmaze(maze); gogo(maze,p-1,q); } if(go==1&&(maze[p+1][q]==0||maze[p+1][q]>=201)){ maze[p+1][q]=3; printrealmaze(maze); gogo(maze,p+1,q); } if(go==2&&(maze[p][q+1]==0||maze[p][q+1]>=201)){ maze[p][q+1]=3; printrealmaze(maze); gogo(maze,p,q+1); } if(go==3&&(maze[p][q-1]==0||maze[p][q-1]>=201)){ maze[p][q-1]=3; printrealmaze(maze); gogo(maze,p,q-1); } //////////////////////////////// if(go==0&&maze[p-1][q]!=0&&maze[p-1][q]<200&&ways!=0){ gogo(maze,p,q); } else if(go==1&&maze[p+1][q]!=0&&maze[p+1][q]<200&&ways!=0){ gogo(maze,p,q); } else if(go==2&&maze[p][q+1]!=0&&maze[p][q+1]<200&&ways!=0){ gogo(maze,p,q); } else if(go==3&&maze[p][q-1]!=0&&maze[p][q-1]<200&&ways!=0){ gogo(maze,p,q); } /////////////////////////////////// else if(ways==0&&(p!=-3+maze[0].size()&&q!=-3+maze.size())){// p=r; q=k; gogo(maze,p,q); } cout<<"GG"<