I wrote DFS method for a direct graph and to check whether there is a cycle or not. Most of my codes are from my class notes and the textbook. The problem is that it says there is no cycle when a cycle exists. I made some changes but the code didn't even run. I'd appreciate your help. Here is my codes for checking a cycle
char check;
char vertex;
int exit=0;
cout<<"Checking to see if there is a DFS cycle";
j=0;
for(i=0;i<columns;i++)
{
vertex=matrix[i][j];
j++;
if(matrix[i][j]!='0')
{
check=matrix[i][j];
j=0;
i=0;
int count=1;
while(exit<rows)
{
if(check==matrix[i][j])
j++;
else
i++;
if(vertex==matrix[i][j]&&count>1)
{
cout<<"This graph has a DFS cycle!";
break;
}
if(vertex!=matrix[i][j]&&check!=matrix[i][j])
{
check=matrix[i][j];
j=0;
i=0;
cout << "This graph has no DFS cycle!";
break;
}
exit++;
}
j=0;
}
else
j=0;
}
system("PAUSE");
return 0;
}