Queue Data Structure Studytonight
Queue Data Structure Studytonight
Queue Data Structure Studytonight
Queue is also an abstract data type or a linear data structure, just like
stack data structure, in which the first element is inserted from one
end called the REAR(also called tail), and the removal of existing
element takes place from the other end called as FRONT(also called
head).
The process to add an element into queue is called Enqueue and the
process of removal of an element from queue is called Dequeue.
Applications of Queue
Queue, as the name suggests is used whenever we need to manage
any group of objects in an order in which the first one coming in, also
gets out first while the others wait for their turn, like in the following
scenarios:
In approach [B] we remove the element from head position and then
move head to the next position.
#include<iostream>
#define SIZE 10
class Queue
public:
Queue()
{
rear = front = -1;
}
int main()
{
Queue q;
q.enqueue(10);
q.enqueue(100);
q.enqueue(1000);
q.enqueue(1001);
q.enqueue(1002);
q.dequeue();
q.enqueue(1003);
q.dequeue();
q.dequeue();
q.enqueue(1004);
q.display();
return 0;
}
return a[0];
for (i = 0; i < tail-1; i++)
{
a[i] = a[i+1];
tail--;
}
Enqueue: O(1)
Dequeue: O(1)
Size: O(1)