c - priority queue, where to insert? -


Therefore, I'm having trouble implementing the priority queue for the priority queue, I need the first place where it is empty ... where the element goes, we will swap later. But I am troubling to find out the algorithm to find out.

Even I have so far:

  zero pq_inert (struct tnode * p) {struct tnode * curr = NULL; Structure tnode * prev = NULL; Printf ("insert:% c, f% \ n", p-> symbol, p-> freq); If (qhead == NULL) / * qhead is empty * / {qhead = p; / * TODO: Type the code to insert when the queue is empty * /} / * TODO: * / curr = qhead Enter the code to find the correct position to enter; While (curr! = NULL) {// I think it is wrong if ((curr -> left) == NULL) {curr = curr -> right; } And {curr = curr - & gt; Left; }} If (curr == qhead) {/ * TODO: insert code to insert before the start of the current * /} and / * insert between the previous and next * / {/ * TODO: code to insert between Type *}}  

Yes, you think the code is incorrect:

  while (curr! = NULL) {// I think this is wrong if ((curr -> left) == NULL) {curr = curr -> right; } And {curr = curr - & gt; Left; }}  

Incorrectly you are going to rotate some part of your tree regardless of your current node.

You probably want to change your interior, such as something:

  if (p-> gt; freq & lt; curr- & gt; freq)  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -