C++ Graph DFS Cycle check
<p>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</p>

<pre><code>char check;
char vertex;
int exit=0;
cout&lt;&lt;"Checking to see if there is a DFS cycle";
j=0;
for(i=0;i&lt;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&lt;rows)
    {
      if(check==matrix[i][j])
        j++;
      else 
        i++;
      if(vertex==matrix[i][j]&amp;&amp;count&gt;1)
      {
        cout&lt;&lt;"This graph has a DFS cycle!";
        break;
      }
      if(vertex!=matrix[i][j]&amp;&amp;check!=matrix[i][j]) 
      {
        check=matrix[i][j];
        j=0;
        i=0;
        cout &lt;&lt; "This graph has no DFS cycle!";
        break;
      }
      exit++;
    }
    j=0;  

  }
  else
    j=0;
  }
  system("PAUSE");
  return 0;
}  
</code></pre>
