so I am having trouble implementing priority queue. For a priority queue, I need to find the first place where it is empty...that's where the element go, we will swap later..but I am having trouble figuring out the algorithm to find it.
Here's what I have so far:
void pq_insert(struct tnode* p)
{
struct tnode* curr=NULL;
struct tnode* prev=NULL;
printf("inserting:%c,%f\n",p->symbol,p->freq);
if(qhead==NULL) /*qhead is null*/
{
qhead = p;
/*TODO: write code to insert when queue is empty*/
}
/*TODO: write code to find correct position to insert*/
curr = qhead;
while (curr != NULL){//I think this is wrong
if ((curr -> left) == NULL){
curr = curr -> right;
}
else{
curr = curr -> left;
}
}
if(curr==qhead)
{
/*TODO: write code to insert before the current start*/
}
else /*insert between prev and next*/
{
/*TODO: write code to insert in between*/
}
}