package graph; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Scanner; /** * @author Sesh Venugopal. */ class Neighbor { public int vertexNum; public Neighbor next; public Neighbor(int vnum, Neighbor nbr) { this.vertexNum = vnum; next = nbr; } } class Vertex { String name; Neighbor adjList; Vertex(String name, Neighbor neighbors) { this.name = name; this.adjList = neighbors; } } class Graph { Vertex[] adjLists; // Keys public Graph(String file) throws FileNotFoundException { Scanner sc = new Scanner(new File(file)); String graphType = sc.next(); boolean undirected=true; if (graphType.equals("directed")) { undirected=false; } adjLists = new Vertex[sc.nextInt()]; // read vertices for (int v=0; v " + adjLists[nbr.vertexNum].name); } System.out.println("\n"); } } /** * @param args */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); System.out.print("Enter graph input file name: "); String file = sc.nextLine(); Graph graph = new Graph(file); //graph.print(); graph.dfs(); } }