Advertisement
Aldin_SXR

graph search main()

May 26th, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.50 KB | None | 0 0
  1. public static void main(String[] args) {
  2.        
  3.     /* Create a graph */
  4.     Graph g = new Graph(6);
  5.     g.addEdge(0, 5);
  6.     g.addEdge(0, 1);
  7.     g.addEdge(0, 2);
  8.     g.addEdge(1, 2);
  9.     g.addEdge(5, 3);
  10.     g.addEdge(3, 2);
  11.     g.addEdge(4, 2);
  12.        
  13.     GraphSearch gs = new GraphSearch(g);
  14.        
  15.     /* Traverse over the graph using DFS */
  16.     System.out.print("DFS: ");
  17.     gs.dfs(0);
  18.        
  19.     /* Reset the search */
  20.     System.out.println();
  21.     gs.reset();
  22.  
  23.     /* Traverse over the graph using BFS*/
  24.     System.out.print("BFS: ");
  25.     gs.bfs(0);
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement