Exp3 Priority Queue 24-25
Exp3 Priority Queue 24-25
Experiment No. : 3
Aim: a) Write a menu driven program to implement a static priority queue supporting following
operations.
1. Create empty queue,
2. Insert an element on the queue,
3. Delete an element from the queue,
4. Display element with highest priority
5. Display all elements of the queue.
__________________________________________________________________________________
__________________________________________________________________________________
Theory:
Queue -
A queue is an ordered list in which insertion and deletion happens two different ends.
The insertion happens from the rear and the deletion takes place at the front. It works
with the FIFO concept i.e. first in first out.
Basic operations of Queue are enqueue, dequeue, isempty, etc.
Priority Queue –
A priority queue is a type of queue that arranges elements based on their priority
values. Elements with higher priority values are typically retrieved or removed before
elements with lower priority values. Each element has a priority value associated with
it. When we add an item, it is inserted in a position based on its priority value.
In a priority queue, generally, the value of an element is considered for assigning the
priority.
For example, the element with the highest value is assigned the highest priority and
the element with the lowest value is assigned the lowest priority. The reverse case can
also be used i.e., the element with the lowest value can be assigned the highest
priority. Also, the priority can be assigned according to our needs.
Methods :
______________________________________________________________________________
Algorithm :
1. createQueue():
This method creates and empty queue
This operation adds an item as per its priority. Before insert operation, ensure that
there is a room for the new item. If there is not enough room, then the queue is in an
‘Overflow’ state.
3. typedef dequeue() :
This operation removes the item with highest priority from the Queue and returns it to
the user. When the last item in the queue is deleted, it must be set to its empty state. If
dequeue is called when the queue is empty, then it’s in an ‘Underflow’ state.
4. typedef peek() :
5. void displayAll():
This operation will display all item present in the queue at that instance.
6. boolean isEmpty() :
This operation will check whether Queue is empty or not at a given instance. The
function will return
0 if Queue is not empty.
1 if Queue is empty.
7. boolean isFull() :
This operation will check whether Queue is full or not at a given instance. The
function will return
0 if Queue is not full.
1 if Queue is full.
_________________________________________________________________________________
Results: A program implementing solution depicting the correct behaviour of priority queues and
capable of handling all possible exceptional conditions and the same is reflecting clearly in the
output.
_________________________________________________________________________________
Outcome:
Conclusion:
Grade: AA / AB / BB / BC / CC / CD /DD:
______________________________________________________________________________
Signature of faculty in-charge with date :
References: