DEPTH FIRST SEARCH IN JAVA

21:06

DEPTH FIRST SEARCH IN JAVA



public void dfs()
 {
  
  vertex[0].visited=true;
  displyVertex(0);
  stackobj.push(0);
  
  while(!stackobj.isEmpty())
  {
   int v=adjVertex((Integer) stackobj.peek());
   if(v==-1)
   {
    stackobj.pop();
   }
    else{
     vertex[v].visited=true;
     displyVertex(v);
     stackobj.push(v);
     
    }
   }
  }
  

You Might Also Like

0 comments