need help to understand this question?

hello guys i cant understand this question
Implement Priority queue using single link list. (Insert input where small value having the max priority.)
what i think i need to do is check the input value with all values already inside th queue and then place it where it belong like if user enter 5 the 5 go after 4


or maybe i just need to put priority with the input number like 5 enter then compare it with already number at front and set the priority of 5 .
Last edited on
A priority queue is a queue which sorts is element according to its values. The question simply asks you to create a queue where the elements with the smallest value will be at the front and the elements with the largest value will be at the back.

To give an example, if we insert 2, 8, 4 and 10 into that queue in that order, the queue will then contain:

2 : 4 : 8 : 10

With 2 being at the front of the queue (it will be the first element to come out of the queue) and 10 will be at the end of the queue.
so lets say user first enter 4 first that go to front then user enter 8 that goto rear after that user enter 2 then i check 2 with front and rear and put 2 at front

thats what you are saying ?
thats what you are saying ?

Exactly. When inserting items into the list, you need to insert them in the right position so that the list stays in priority order.
Topic archived. No new replies allowed.