Note that there are some explanatory texts on larger screens.

plurals
  1. POCan Priority Queues have empty elements (like arrays)?
    primarykey
    data
    text
    <p>Hi I am writing an algorithm in algorithm design language for a mock test, for adding an element to a priority-queue. </p> <p>Now I plan to do this by using the general method of inserting an element into a regular queue at the back and then sorting it into correct place by comparing it (according to priority value) to the element that is positioned before it in the priority-queue.</p> <p>This is the algorithm I have so far (only for adding items to the priority-queue):</p> <ul> <li><em>element</em>- element to be added to the queue.</li> <li><em>queue[ ]</em>- priority queue element is being added to.</li> <li><em>n</em>- the size of the priority queue.</li> <li><em>tail</em>- the last element in the priority queue.</li> </ul> <p><strong>procedure</strong> AddQ (<strong>IN</strong> element, <strong>INOUT</strong> queue[ ], <strong>IN</strong> n, <strong>INOUT</strong> tail) </p> <pre><code>if tail= n then print (“Queue is full”) else { tail← tail+ 1 queue (tail) ← element } </code></pre> <p><strong>end</strong></p> <p>What I am not sure of is should I have the section which prints that the Queue is full. Am I right is thinking that priority queues have a pointer in the tail element pointing to null to say that there are not elements left?</p> <p>If so does this mean that priority-queues cannot have empty space (like a standard array for example)for new elements as the tail in the priority-queue points to null, saying no more elements are in the queue? Or am I taking the wrong approach here?</p> <p>I am confused as to how this works, if someone could clarify I would be very grateful! Thankyou.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload