for(i=1; i<=n-1; i++)
{
p = deque(PQ);
q = deque(PQ);
r = new nodetype;
r.left = p;
r.right = q;
r.frequency = p.frequency + q.frequency;
enque(PQ, r); // put in the correct place in the priority queue
}
p = deque(PQ); // leave the priority queue empty
return(r); // this is the root of the tree built