For my CS class I need to implement Prim's algorithm in Java and I am having problems with the priority queue step. I have experience with priority queues and understand they work in general but I am having trouble with a particular step.
Prim(G,w,r)
For each u in V[G]
do key[u] ← ∞
π[u] ← NIL
key[r] ← 0
Q ← V[G]
While Q ≠ Ø
do u ← EXTRACT-MIN(Q)
for each v in Adj[u]
if v is in Q and w(u,v) < key[v]
then π[v] ← u
key[v] ← w(u,v)
I've created a Node class that contains the key value(which I assume is the lightest edge connected to the Node) and the parent Node. My problem is that I don't understand adding the Node to the priority queue. Adding all the Nodes to the priority queue doesn't not make sense to me when the parent has been set to NIL and the key to ∞.