### [help] DFS, cant find my mistake...

I have a DFS algorithm here, and when i run the thing and try to find the path, my console stops responding (it crashes), so i would like to ask if anyone can tell me what is wrong?? -I worked on this for hours but cant identify the problem.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161`` ``````#include #include #include using namespace std; void menu(){ cout << "DFS " << endl; cout << "1) Read graph from file" << endl; cout << "2) Search: s - d " << endl; cout << "3) EXIT" << endl << endl; } struct Vert{ int name; int elder; int depth; int status; }; int size; int C[30][30]; void read(string f){ fstream dat(f.c_str(), fstream::in); dat >> size; int i=0; int p, q, c; while(!dat.eof()) { dat >> p >> q >> c; C[p-1][q-1] = c; C[q-1][p-1] = c; i++; } dat.close(); } int top; int stacks[30]; void PUSH(int v){ stacks[top]=v; top++; } int POP(int a){ top--; stacks[top]=a; return stacks[top]; } void DEPTH_SEARCH(int C[30][30], int vel, int s){ Vert V[30]; for(int x=0; x> select; cout << endl; switch(select){ case 1: read("graph.txt"); cout << "size: " << size << endl; for(int j=0;j> s; cout << endl; cout << "Enter d: "; cin >> d; cout << endl; DEPTH_SEARCH(C, vel, s); PRINT_PATH(V, s, d); break; case 3: break; } }while(select!=3); system("PAUSE"); return 0; } ``````
Try
 ``1234567891011`` ``````using namespace std; void menu(void) { cout << "DFS " << endl; cout << "1) Read graph from file" << endl; cout << "2) Search: s - d " << endl; cout << "3) EXIT" << endl << endl; } ``````
no, doesnt work, still gives: '...stopped working' and my programme crashes...

It runs fine, but when i press 2, to call the DEPTH_SEARCH function, it crashes...
_ Uninitialized variables
_ Bad reading (that may cause invalid access). Don't loop on eof

Provide an example run.
Also, perform a backtrace when it crashes
Topic archived. No new replies allowed.