Aldin_SXR

edge-weighted main()

May 26th, 2020
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. public static void main(String[] args) throws FileNotFoundException {
  2.        
  3.     /* Read a digraph from a file */
  4.     EdgeWeightedGraph ewg = new EdgeWeightedGraph(
  5.             new Scanner(new File("/home/aldin-sxr/Downloads/tinyEWG.txt")));
  6.        
  7.     System.out.println("Number of vertices: " + ewg.V());   // 8
  8.     System.out.println("Number of edges: " + ewg.E());      // 16
  9.        
  10.     /* See adjacent vertices of vertex 0 */
  11.     /* Expected: 7, 4, 2, 6 */
  12.     System.out.println("Adjacent vertices of 0: ");
  13.     Iterable<Edge> vertices = ewg.adj(0);
  14.     for (Edge e: vertices) {
  15.         System.out.println(e.other(0) + ": " + e.weight());
  16.     }
  17.    
  18. }
Add Comment
Please, Sign In to add comment