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

Data Structures & Algorithms

The document discusses circular queue data structures. A circular queue can overcome the re-buffering problem of normal queues by allowing insertion from the rear and deletion from the front. It describes the basic operations of enqueue, dequeue, and peek. Pseudocode algorithms are provided for enqueue and dequeue operations in a circular queue implemented using an array.

Uploaded by

Huzaifa Ubaid
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)
63 views

Data Structures & Algorithms

The document discusses circular queue data structures. A circular queue can overcome the re-buffering problem of normal queues by allowing insertion from the rear and deletion from the front. It describes the basic operations of enqueue, dequeue, and peek. Pseudocode algorithms are provided for enqueue and dequeue operations in a circular queue implemented using an array.

Uploaded by

Huzaifa Ubaid
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/ 9

DATA STRUCTURES &

ALGORITHMS
Lecture By: Mr. Saeed Ur Rehman
03036423161.
Department of CS/IT
Khwaja Fareed University of Engineering &
Information Technology
Circular Queue
• In a normal Queue Data Structure, elements
can be inserted until queue is full. But once if
queue becomes full, the next element can‟t
be inserted until all the elements are deleted
from the queue. For example consider the
queue below: After inserting all the elements
into the queue:
CQUEU Example
C Queu Example
C QUEU Data Structure
• This situation also depicts that Queue is Full and
we cannot insert the new element because, 'rear'
is still at last position. In above situation, even
though we have empty positions in the queue we
cannot make use of them to insert new element.
This is the major problem in normal queue data
structure using array implementation. This
problem is known as re- buffering problem. To
overcome this problem we use circular queue
data structure. Circular queue is also known as
“Ring Buffer.”
Circular Queue
• A circular queue can be implemented by
means of Array, Structure, Pointer, and Linked
List.
• Insertion takes place from REAR (TAIL) only
and is called EnQueue.
• Deletion takes place from FRONT (HEAD) only
and is called DeQueue.
• Initially when queue is empty FRONT and
REAR both are NULL.
Basic Operation
• EnQueue–add (store) an item to the circular
queue.
• 2. DeQueue – remove an item from the
circular queue. 3
• . PEEK– Gets the element at the front of the
circular queue without removing it. 4
• . Display − Displays the complete circular
queue.
Enqueue ( Cicular Queue) Algo
• Enqueu_Cqueue(Cqueue, Rear, Front, item,)
• Staert
• Check overflow()
• If Front = = o and Rear = = size-1
• Print “ Queue is Overflow” &
• Exit
• [End of if]
• Else
• If Front = = Null & Rear = = Null then
• Set Front = = 0
• Set Rear = = 0
• Set Cqueue[Rear] = item
• If Rear = = N-1
• Set Rear = 0
• Set Cqueue[Rear] = item
• Else
• Set Rear = Rear+1
• Set Cqueue[Rear] = item
• [End of else]
• STOP
Dequeu(Circular Queue) Algo
• Dequeue_Cqueue(Cqueue, Front, Rear, Item)
• START
• Check underflow()
• If Front = = Null then
• Print “Underflow “ &
• Exit.
• [End of if ]
• Else
• If Front = Rear Then
• Delete has on One Element at Front
• Set Front = = Null & Rear = = Null
• Elss if Front = N-1 Then
• Delete At Last Position.
• Set Front = 0
• Else
• Delete item at Front Position any where
• Set Front = Front + 1
• [End of else]
• Stop

You might also like