Question: Create a class: AdjListGraph.java, and just submit AdjListGraph.java. where Please implement a graph by adjacency list Write a method: void dfs(){TO-DO}; which can traverse a

Create a class: AdjListGraph.java, and just submit AdjListGraph.java. where Please implement a graph by adjacency list Write a method: void dfs(){\\TO-DO}; which can traverse a graph by DFS (stack based or recursive) The class adjListGraph.java will be test as public class Test {public static void main(String[] args) {AdjListGraph theGraph = new AdjListGraph (); theGraph.addVertex('A');//0 (start for dfs) theGraph.addVertex('B');//1 theGraph.addVertex('C');//2 theGraph.addVertex('D');//3 theGraph.addVertex('E');//4 theGraph.addVertex('F');//5 theGraph.addEdge(0, 1);//AB theGraph.addEdge(0, 2);//AC theGraph.addEdge(1, 3);//BD theGraph.addEdge(2, 4);//CE theGraph.addEdge(2, 3);//CD theGraph.addEdge(0, 3);//AD theGraph.addEdge(3, 4);//DE theGraph.addEdge(3, 5);//DE System.out.print ("dfs visits:----------------------- "); theGraph.dfs(); System.out.println();}//end main ()}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
