0% found this document useful (0 votes)
3 views

Queue

The document provides an overview of queues in data structures, explaining their linear nature where deletions occur at the front and insertions at the rear. It details two main implementations of queues: circular queues using arrays and linked lists, highlighting their operational differences and capabilities. Additionally, the document includes C++ code examples for implementing both types of queues.

Uploaded by

baktiavishek
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Queue

The document provides an overview of queues in data structures, explaining their linear nature where deletions occur at the front and insertions at the rear. It details two main implementations of queues: circular queues using arrays and linked lists, highlighting their operational differences and capabilities. Additionally, the document includes C++ code examples for implementing both types of queues.

Uploaded by

baktiavishek
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Data Structure

ICT 2101
Dr. Mohammad Abu Yousuf
[email protected]

1
Queue

2
• A queue is a linear list of elements in which deletion can
take place only at one end, called the front, and
insertions can take place only at the other end, called the
rear.

• The term “front” and “rear” are used in describing a


linear list only when it is implemented as a queue.

3
• There are main two ways to implement a queue :
– 1. Circular queue using array
– 2. Linked Structures (Pointers)

• When a queue is implemented using array, that queue


can organize only limited number of elements.

• When a queue is implemented using linked list, that


queue can organize unlimited number of elements

4
• Primary queue operations:
– Enqueue: insert an element at the rear of the queue
– Dequeue: remove an element from the front of the
queue

5
Insertion in Queue

6
Deletion in Queue

7
Queue Example
• Following Figure shows that how a queue may be
maintained by a circular array with MAXSIZE = 6 (Six
memory locations).
• Observe that queue always occupies consecutive
locations except when it occupies locations at the
beginning and at the end of the array.
• If the queue is viewed as a circular array, this means that
it still occupies consecutive locations. Also, as indicated
by Fig(k), the queue will be empty only when Count = 0
or (Front = Rear but not null) and an element is deleted.
• For this reason, -1 (null) is assigned to Front and Rear.
8
9
10
11
C++ Code to implement Circular QUEUE using array

12
C++ Code to implement Circular QUEUE using array

13
C++ Code to implement Circular QUEUE using array

14
Queue using Linked List
• In linked list implementation of a queue, the last inserted
node is always pointed by 'rear' and the first node is
always pointed by 'front'.
• To implement queue using linked list, we need to set the
following things before implementing actual operations.

15
Queue using Linked List

• enQueue(value) - Inserting an element into the Queue:

16
Queue using Linked List

• deQueue() - Deleting an Element from Queue:

17
Queue using Linked List

• display() - Displaying the elements of Queue:

18
Program for Queue Using Linked List

19
Program for Queue Using Linked List

20
Program for Queue Using Linked List

21
Thank You

22

You might also like