You can find the foundation for this program here : http://algs4.cs.princeton.edu/43mst/PrimMST.java