Implementation of Prims Algorithm in Java