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); } } }
Comments
Post a Comment