Beruflich Dokumente
Kultur Dokumente
Chapter 5:
Queue
Imran Ali Memon
Lecturer (IT Department)
Rear Front
QUEUE
Contents
5.1 - Introduction
5.2 – Basic Operations
5.3 – Types of representation of queue in memory
5.4 – enqueue( ) Algorithm
5.5 – dequeue( ) Algorithm
5.6 – Types of queues
Front = 3901
Rear = 1001
Front = 3901
Rear = 1001
Head
1111
enqueue()
AAA 1050 BBB 2000 CCC 3901 DDD
1001 1050 2000 3901
Front = 3901
New 1001
1111 Imran Ali Memon (Lecturer IT Department)
Rear = 1111 10
Linked List Representation of Queue(Dynamic)
Head
1001
Front = 3901
Rear = 1001
Head
1001
dequeue()
AAA 1050 BBB 2000 CCC
1001 1050 2000
Front = 2000
Imran Ali Memon (Lecturer IT Department)
Rear = 1001 11
Array Representation of Queue
• Usually the queues are represented in the computer
by a linear array.
• Each of our queues will be maintained by a linear
array QUEUE and two pointer variables FRONT and
REAR.
• FRONT containing the location of the front element
of the queue.
• REAR containing the location of the rear element of
the queue .
• FRONT = NULL indicates the queue is empty.
Imran Ali Memon (Lecturer IT Department) 12
Array Representation of Queue
Next slide shows:
• The way the array will be stored in memory using an array
QUEUE with N elements.
• Way the elements will be deleted from queue.
• Way new elements will be added to the queue.
• Whenever an element is deleted from the queue, the value
of FRONT is increased by 1.
• FRONT = FRONT + 1;
• Whenever an element is added to the queue, the value of
REAR is increased by 1.
• REAR = REAR + 1; Imran Ali Memon (Lecturer IT Department) 13
Array representation of the queue
F R
0 1 2 3 4 5 6 7 8 9 10 11
FRONT = 0
REAR= 3 A B C D
0 1 2 3 4 5 6 7 8 9 10 11
FRONT= 1
REAR = 3 B C D
0 1 2 3 4 5 6 7 8 9 10 11
FRONT = 1
REAR= 4 B C D E
FRONT=2 0 1 2 3 4 5 6 7 8 9 10 11
REAR = 5 C D E F
Imran Ali Memon (Lecturer IT Department) 14
Array representation of the queue
0 1 2 3 4 5 6 7 8 9 10 11
0 1 2 3 4 5 6 7 8 9 10 11
FRONT = 0
REAR= 0
A
Node