![]() |
What is a circular Queue?
Mainly it is used in memory management, process scheduling, and traffic systems, and also o good for serial data stream operation in Embedded systems. Operations on Circular Queue:
Full Circular Event (Overflow):
Initially, when such a queue is empty, the “front” and the “rear” values are 0 & -1 respectively; and the queue has a NULL value for its entire element. Every time we add an element to the queue, the “rear” value increments by 1 until it reaches the queue’s upper limit; after which it starts over again from 0. Similarly, every time we delete an element from the queue, the “front” value increments by 1 until it reaches the queue’s upper limit; after which it starts over again from 0. Managing Full Circular Queue
Pseudo Codes:Enqueue operation:
Dequeue operation:
Below is the implementation of the above approach. C++
Java
Python3
C#
Javascript
Output
Elements in Circular Queue are: 14 22 13 -6 Deleted value = 14 Deleted value = 22 Elements in Circular Queue are: 13 -6 Elements in Circular Queue are: 13 -6 9 20 5 Queue is Full Time Complexity: Time complexity of enQueue(), deQueue() operation is O(1) as there is no loop in any of the operation. When to use full circular queue?A full circular queue is used in situations where a traditional linear queue is not suitable. The main advantage of a circular queue over a linear queue is that it allows for more efficient memory usage in certain cases. Here are some common scenarios where a full circular queue is used:
Related Articles:
|
Reffered: https://www.geeksforgeeks.org
Data Structures |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 18 |