Professional Documents
Culture Documents
Hamdard University
LAB SESSION 05
QUEUES AND PRIORITY QUEUES
Objectives:
Definition:
A queue is a special type of linear structure. It holds a series of items for processing on a first element on a first
in first out basis. Elements can only be inserted to the back of a queue. Only the front elements can be accessed
and modified.
A queue is a FIFO (First In First Out) Structure. In Queue inserting an element is known as ENQUEUE and is done
at the REAR end of the queue. Deletion of an element is called DEQUEUE and is done at the FRONT end. An
element in a queue is called an ITEM. The number of elements that a queue can accommodate is termed as
LENGTH.
Representation of Queues:
There are two ways to represent a queue in memory:
Using an array
Operation on Queues:
Different operations can be performed on queues like:
Enqueue
Dequeue
Display Queue
IsFull()
IsEmpty()
etc
queue is Empty
if (front==NULL)
display "Stack Empty " and exit else goto 2
2. Set temp=front
3. Adjust fron
front=front->next
4. Display temp->info
5.Free(temp)
6.Exit
Lab Task
1) Write and execute the example given in priority queue, Check if it is ascending priority queue or
descending priority queue. Write the code for the vice versa. Also implement Enqueue () and Dequeue()
methods.
2) Implement the priority queue using pointers. Also implement Enqueue () and Dequeue() methods.
3) Write a code that searched for first three highest elements in the queue.
4) Write a code that inputs five elements in a queue and displays the average of those elements.
5) Write a program to insert ten names into a priority queue. Print all the names from the priority queue
that have the top priority.