-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMSTAnimation_MiS.java
More file actions
32 lines (32 loc) · 1.05 KB
/
MSTAnimation_MiS.java
File metadata and controls
32 lines (32 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import edu.princeton.cs.algs4.*;
import java.util.Iterator;
/**
* Write a client program that does dynamic graphical animations of MST algorithms.
It is not an interactive animation.
*
* @mseskar
* @4/6/18
*/
public class MSTAnimation_MiS
{
public static void main(String[] args){
In in = new In(args[0]);
EdgeWeightedGraph g = new EdgeWeightedGraph(in);
StdDraw.setXscale(-0.05,1.05);
StdDraw.setYscale(-0.05,1.05);
int X = g.X();
double[] xcoords = new double[X];
double[] ycoords = new double[X];
for(int i = 0; i<X; i++){
xcoords[i] = Math.random();
ycoords[i] = Math.random();
StdDraw.filledCircle(xcoords[i],ycoords[i],0.01);
}
KruskalMST mst = new KruskalMST(g);
Iterator<Edge> itr = mst.edges().iterator();
while(itr.hasNext()){
Edge edge = itr.next();
StdDraw.line(xcoords[edge.either()],ycoords[edge.either()], xcoords[edge.other(edge.either())], ycoords[edge.other(edge.either())]);
}
}
}