Implementation of Circular Queue using Arrays in java
Implementation of Circular Queue using Arrays
Circular Queue is a linear data structure in which the operations are performed based on FIFO (First In First Out) principle and the last position is connected back to the first position.
Why we need circular queue ??
When we work with normal Queue, we can insert elements till queue is full. But when queue is full, we are not allowed to insert the next element this is the problem with normal queue . To overcome this problem circular queue is used .
Operation In Circular Queue:
The following are the operations that can be performed on a circular queue:
- Front: It is used to get the front item from the Queue.
- Rear: It is used to get the last element from the Queue.
- enQueue(value): This function is used to insert the new value in the Queue. The new element is always inserted from the rear end.
- deQueue(): This function deletes an element from the Queue. The deletion in a Queue always takes place from the front end.
Algorithm for Insertion:
- INITIALLY PUT FRONT AND REAR BOTH AS 0
- IN ENQUEUE FUNCTION WRITE
public static void enqueue(int item)
Algorithm for Deletion:
- WRITE dequeue function as
elements in queue are
element deleted is 20
elements in queue after deletion