Draw your graph:
q = graph.getEdges().sortAscending()
mst = []
while(mst <
graph.numVertices()-1)
next = q.popFirst()
if(!formsCycle(mst,
next))
mst.push(next)
SHORT EXPLANATION
---------------------
1. Sort all edges by weight (non-decreasing).
2. Pick the edge with the smallest weight.
3. Check if adding that edge to the MST forms a cycle. If
it doesn't, add it.
4. Repeat steps 2 and 3 until MST has a lenght of (number
of Vertices - 1).