title: non recursive depth first search behaving almost like c#
body: <p>I'm trying to  implementnon recursive  DFS algorithm in c#
    here is my method code </p>
  
  <pre><code>public void dfs(int vertex)
  {
     int length = matrix.GetLength(0);
     bool[] visited = new bool[length]; 
     for (int k = 0; k &lt; length; k++)
     {
       visited[k] = false; 
     }
     Stack&lt;int&gt; vertexStack = new Stack&lt;int&gt;();
     vertexStack.Push(vertex);
     visited[vertex] = true;
     Console.Write((vertex) + " ");
     while (vertexStack.Count() != 0)
     {
          int tempVertex = vertexStack.Peek();
          for (int j = 0; j &lt; length; j++)
          {
              if (matrix[tempVertex, j] == 1 &amp;&amp; !visited[j])
              {
                  Console.Write(j + " ");
                  visited[j] = true;
                  vertexStack.Push(j);
              }
          }
          vertexStack.Pop();    
     }
  }
  </code></pre>
  
  <p>and here is my graph code</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  namespace ConsoleApplication1
  {
      class Program
     {
      static void Main(string[] args)
      {
  
          int[,] matrix2 = {
          {0,1,1,1,0,0},
          {1,0,0,0,1,1},
          {1,0,0,0,0,1},
          {1,0,0,0,0,0},
          {0,1,0,0,0,0},
          {0,1,1,0,0,0},
                           };
          Graphs g2 = new Graphs(matrix2);
          g2.dfs(0);
         // Console.ReadKey();
       }
     }
  }
  </code></pre>
  
  <p>for this graph  the result of the dfs shoud be  0 1 4 5 2 3</p>
  
  <p>but they are 0 1 2 3 5 4 which is almost like BFS for  this graph 0 1 2 3 4 5</p>
  
  <p>can anyone tell me What's wrong here ?</p>