title: Depth First Traversal and Adj Matrix
body: <p>I'm trying to do a depth first traversal. I have no idea if I'm even close. Right now it's printing 1 3 4 5. It should be printing 1 2 4 7 3 5 6. Any help or advice is appreciated. Thanks. :)</p>
  
  <p><img src="https://i.stack.imgur.com/ABq58.png" alt="enter image description here"></p>
  
  <p>Class:</p>
  
  <pre><code> public class myGraphs {
       Stack&lt;Integer&gt; st;
       int vFirst;
  
       int[][] adjMatrix;
       int[] isVisited = new int[7];
  
  
       public myGraphs(int[][] Matrix) {
           this.adjMatrix = Matrix;
           st = new Stack&lt;Integer&gt;();
           int i;
           int[] node = {1, 2, 3, 4, 5, 6, 7};
           int firstNode = node[0];
  
           for (i = 1; i &lt; node.length - 1; i++) {
               depthFirst(firstNode, node[i]);
           }
      }
  
      public void depthFirst(int vFirst, int n) {
          int v, i;
  
          st.push(vFirst);
  
          while (!st.isEmpty()) {
              v = st.pop();
              if (isVisited[v]==0) {
                  System.out.print("\n"+v);
                  isVisited[v]=1;
              }
  
              for ( i=1;i&lt;=n;i++) {
                  if ((adjMatrix[v][i] == 1) &amp;&amp; (isVisited[i] == 0)) {
                      st.push(v);
                      isVisited[i]=1;
                      System.out.print(" " + i);
                      v = i;
                  }
              }
          }
      }
  
      //
      public static void main(String[] args) {     
          // 1  2  3  4  5  6  7
          int[][] adjMatrix = { {0, 1, 1, 0, 0, 0, 0},
                                {1, 0, 0, 1, 1, 1, 0},
                                {1, 0, 0, 0, 0, 0, 1},
                                {0, 1, 0, 0, 0, 0, 1},
                                {0, 1, 0, 0, 0, 0, 1},
                                {0, 1, 0, 0, 0, 0 ,0},
                                {0, 0, 1, 1, 1, 0, 0}  };
  
         new myGraphs(adjMatrix);
       }
  }
  </code></pre>