Queue Data Structure
Queue Data Structure
STRUCTURE
QUEUE DATA STRUCTURE
A Queue Data Structure is a fundamental concept in computer science used for
storing and managing data in a specific order. It follows the principle of “First in, First
out” (FIFO), where the first element added to the queue is the first one to be
removed.
BASIC OPERATIONS OF QUEUE
A queue is an object (an abstract data structure - ADT) that allows the
following operations:
Enqueue: Add an element to the end of the queue
Dequeue: Remove an element from the front of the queue
IsEmpty: Check if the queue is empty
IsFull: Check if the queue is full
Peek: Get the value of the front of the queue without removing it
WORKING OF QUEUE
Queue operations work as follows:
circularly increase the REAR index by 1 (i.e. if the rear reaches the end,
for the last element, reset the values of FRONT and REAR to -1
CIRCULAR QUEUE OPERATION
CIRCULAR QUEUE OPERATION
CIRCULAR QUEUE OPERATION
CIRCULAR QUEUE OPERATION
CIRCULAR QUEUE OPERATION
CIRCULAR QUEUE OPERATION
void enque (int x){
if (front==-1 && rear==-1){
front=rear=0;
queue[rear]=x;
}
else if((rear+1)%N)==front){
queue is full
}
else{
rear=(rear+1)%N;
queue[rear]=x;
}
}
CIRCULAR QUEUE OPERATION
void enque (int x){
if (front==-1 && rear==-1){
front=rear=0;
queue[rear]=x;
}
else if((rear+1)%N)==front){
queue is full
}
else{
rear=(rear+1)%N;
queue[rear]=x;
}
}
CIRCULAR QUEUE OPERATION
void enque (int x){
if (front==-1 && rear==-1){
front=rear=0;
queue[rear]=x;
}
else if((rear+1)%N)==front){
queue is full
}
else{
rear=(rear+1)%N;
queue[rear]=x;
}
}
CIRCULAR QUEUE OPERATION
void enque (int x)
{
if (front==-1 && rear==-1)
{
queue is empty
}
else if(front==rear)
{
front=rear=-1;
}
else
{
front=(front+1)%N;
}
}
DOUBLE-ENDED QUEUE
The deque stands for Double Ended Queue. Deque is a linear data structure
where the insertion and deletion operations are performed from both ends.
Though the insertion and deletion in a deque can be performed on both
ends, it does not follow the FIFO rule.
DOUBLE-ENDED QUEUE-TYPES
There are two types of deque -
Input restricted queue
Output restricted queue