I won't write the actual code, but I'll give you tips. These come directly from the CLRS Algorithms textbook.
This is what essentially all MST algorithms must do:
Code:
/* G is your graph, W could be a function pointer to find weights */
/* A is a subset of a minimum spanning tree */
Generic MST Algorithm(G, W)
A = nil
While A does not form a spanning tree
Find a safe edge and add it to A
Return A
Since you said you needed to use a heap, you can implement a priority queue as a heap and use Prim's Algorithm.
Code:
/* G is your graph, W could be a function pointer for finding weights */
/* r is the vertex we start at, AKA the root of the MST */
/* Q is the priority queue implemented via binary heap */
Prim's Algorithm(G, W, r)
For each vertex u in G.V /* G.V is the vertex set of the graph */
u.key = infinity /* distance from r */
u.parent = nil
r.key = 0
Insert into Q all vertices from G.V /* sort by key value */
While Q is not empty
vertex u = dequeue(Q) // u is vertex with next smallest key value
For each vertex v that is adjacent to u
If v is in Q and W(u,v) < v.key
v.parent = u
v.key = W(u,v)