Advertisement
Aldin_SXR

prim main()

May 28th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1. public static void main(String[] args) throws FileNotFoundException {
  2.        
  3.     /* Read an edge-weighted graph from a file */
  4.     EdgeWeightedGraph ewg = new EdgeWeightedGraph(
  5.             new Scanner(new File("/home/aldin-sxr/Downloads/tinyEWG.txt")));
  6.        
  7.     /* Instantiate the lazy Prim's algorithm */
  8.     LazyPrimMST prim = new LazyPrimMST(ewg);
  9.        
  10.     /* Print out MST edges*/
  11.     Iterable<Edge> edges = prim.edges();
  12.     for (Edge e: edges) {
  13.         System.out.println("(" +
  14.                 e.either() + ", " +
  15.                 e.other(e.either()) + ") - " + e.weight());
  16.     }
  17.        
  18.     /* Print out MST weight */
  19.     System.out.println("MST weight: " + prim.weight());
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement