### how to traverse a graph?

hi im trying to make a program that will get a graph inputed from the the user and then checks if it has a cycle. i have written the program but for some reason i cant get it to check for the cycle it starts but somewhere it stops some help would be much appreciated :)

here is my code

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118`` ``````#include using namespace std; int main() { int rows, columns, edges; cout<<"Please enter the amount of vertices: "; cin>>rows; char** matrix; // makes this array into a pointer matrix=new char*[rows]; // to initialize the rows (1 dimensional array for now) cout<<"please enter each vertex"<>matrix[i][j]; // inputs that vertex into the certain location (ex- when start first goes into row 0, column 0...etc.) cout<<"how many edges: ";//each vertex can have 1 or more edges or 0 cin>>edges; j++;// need to move down one row in order to put in the vertex corresponding edges while(j>matrix[i][j]; j++;//need to move down one row in order to put in the vertex corresponding edges } while(j1) { cout<<"this graph has a cycle!"; break; } if(vertex!=matrix[i][j]&&check!=matrix[i][j])// makes sure the next vertex choosen is different { check=matrix[i][j];//set that new vertex into check j=0;//restart for search i=0;//restart for search count++;// another jump is made } exit++; } j=0; } else j=0; } system("pause"); return 0; } ``````
Topic archived. No new replies allowed.