9 Queue 1
9 Queue 1
9 Queue 1
• The first element in a queue will be the first one to be removed from
the list.
• Queues are also called FIFO (First In First Out) i.e. the data item
stored first will be accessed first
Queue Representation
• In queue, we access both ends for different reasons
Applications of queue
• Serving requests on a single shared resource, like a printer, CPU task
scheduling etc.
• In real life, Call Center phone systems will use Queues, to hold people
calling them in an order, until a service representative is free.
3
an array to store data
an integer type variable usually called the FRONT, 30
2
which points to the beginning of the array and an
2 20 1
integer variable REAR, which points to the end of
the filled array. REAR
10 0
0
FRONT
Empty Queue
• As items are removed from the queue, the storage space at the
beginning of the array is discarded and never used again.
• Wastage of the space is the main problem with linear queue which is
illustrated by the following example.
Circular queue
• A queue where the start and end of the queue are joined together.
Rear
Rear Rear
Front
Front
Front
Rear
Rear
Front
1. In a circular queue, if rear reaches to MAX-1 index, then set rear to 0 i.e. 0th index.
2. In a circular queue, if front reaches to MAX-1 index, then set front to 0 i.e. 0th index.
3. At any time, the position of element to be inserted is calculated by
4. After deleting an element from circular queue, the position of front end is calculated by
or