title: Convert Depth First search to Depth Limited Search
body: <p>This is my complete code in java, i would like to apply Depth limited search on it. Can someone please help me?</p>
  
  <p>output: S>A>B>C>D>G</p>
  
  <p>Note: S(0) = Start, G(5) = Goal
  The depth first search is applied using adj matrix.</p>
  
  <pre><code>import java.util.Stack;
  
  
  public class DFS {
  
  Stack&lt;Integer&gt; st;
    int vFirst;
  
    int[][] adjMatrix;
    int[] isVisited = new int[6];
  
  /**
   * @param args
   */
  public static void main(String[] args) {
      int[][] adjMatrix = {
             //S, A, B, C, D, G, 
              {0, 1, 0, 1, 0, 0},
              {1, 0, 1, 0, 1, 0},
              {0, 1, 0, 1, 0, 1},
              {1, 0, 1, 0, 1, 0},
              {0, 1, 0, 1, 0, 1},
              {0, 0, 1, 0, 1, 0},
               };
  
  
    new DFS(adjMatrix);
  
  }
  
  public DFS(int[][] Matrix) {
  
       this.adjMatrix = Matrix;
       st = new Stack&lt;Integer&gt;();
       //int i;
       int[] node = {0, 1, 2, 3, 4, 5};
       int firstNode = node[0];
       depthFirst(firstNode, 6);
  
  
  
        }
  
        public void depthFirst(int vFirst,int n)
        {
        int v,i;
        char out=' ';
  
        st.push(vFirst);
  
        while(!st.isEmpty())
        {
            v = st.pop();
            if(v==0)out='S';
            else if(v==1)out='A';
            else if(v==2)out='B';
            else if(v==3)out='C';
            else if(v==4)out='D';
            else if(v==5)out='G';
  
            if(isVisited[v]==0)
            {
                System.out.print("\n"+out);
                isVisited[v]=1;
            }
            for ( i=0;i&lt;n;i++)
            {
                if((adjMatrix[v][i] == 1) &amp;&amp; (isVisited[i] == 0))
                {
                    st.push(v);
                    isVisited[i]=1;
                    if(i==0)out='S';
                    else if(i==1)out='A';
                    else if(i==2)out='B';
                    else if(i==3)out='C';
                    else if(i==4)out='D';
                    else if(i==5)out='G';
                    System.out.print("-&gt; " + out);
                    v = i;
                }
            }
            }
  }
  }
  </code></pre>