Implementation of Queue
Various Implementation of queue ie. Enqueue and Dequeue
Implementation of the queue using 1 pointer i.e Front
int front = -1;
// Enqueue using only front pointer
void enqueue(int val)
{
int len = v.size();
if ((front + 1) > len - 1)
{
cout << "Queue Full"
<< "\n";
return;
}
else
{
front = front + 1;
v[front] = val;
}
}
// Dequeue using only front pointer
void dequeue()
{
if (front == -1)
{
cout << "Queue Empty"
<< "\n";
return;
}
for (int i = 0; i < v.size() - 1; i++)
{
v[i] = v[i + 1];
}
front = front - 1;
}Implementation of queue using 2 pointers i.e Front and Rear
Implement Queue using LL
Last updated