import java.io.File; import java.io.FileReader; import java.util.Iterator; import java.util.Scanner;
public class useGraph1 { public static void main(String[] args) { Graph theGraph = null; int numVertices = 0; try { // Construct Scanner for input file. Scanner scan = new Scanner(new FileReader(new File("Data/Fig10.25.txt"))); int numV = scan.nextInt(); scan.nextLine(); // Load the graph data from a file. theGraph = new Graph(numV, true); theGraph.readGraph(scan); } catch (Exception ex) { ex.printStackTrace(); System.exit(1); // Error exit. } // Print out the graph System.out.println("The graph has " + theGraph.getNumV() + " vertices."); System.out.println(theGraph); //System.out.println("Depth-first Traversal:"); //theGraph.dfTraversal(); //System.out.println("\n-----\nDepth-first Traversal:"); //theGraph.depthFirst(); System.out.println("Breadth-first Traversal:"); theGraph.bfTraversal(); } }