1: // @author Frank M. Carrano, Timothy M. Henry
2: // @version 5.0
3: GraphInterface<String> roadMap = new UndirectedGraph<String>();
4: roadMap.addVertex("Provincetown");
5: roadMap.addVertex("Truro");
6: // . . .
8: roadMap.addVertex("Falmouth");
9: roadMap.addEdge("Provincetown", "Truro", 10);
10: // . . .
12: roadMap.addEdge("Hyannis", "Falmouth", 20);
14: StackInterface<String> bestRoute = new LinkedStack<String>();
15: double distance = roadMap.getCheapestPath("Truro", "Falmouth", bestRoute);
16: System.out.println("The shortest route from Truro to Falmouth is " +
17: distance + " miles long and " +
18: "passes through the following towns:");
19: while (!bestRoute.isEmpty())
20: System.out.println(bestRoute.pop());