De Queue
De Queue
Deque or Double Ended Queue is a type of queue in which insertion and removal of elements can
either be performed from the front or the rear. Thus, it does not follow FIFO rule (First In First Out).
Types of deQueue
★ Input Restricted Dequeue
In this dequeue, insertion is restricted at a single end but allows deletion at both the ends.
★ Insertion at front
★ Insertion at rear
★ Deletion at front
★ Deletion at rear
We can also perform peek operations in the dequeue along with the
operations listed above. Through peek operation, we can get the front
and rear elements of the dequeue.
★ Get the front item from the
dequeue
★ Get the rear item from the dequeue
★ Check whether the dequeue is full
or not
if (*pfront == -1) {
if (*pfront == -1) {
printf("deQueue is empty.\n");
printf("deQueue is empty.\n");
return 0;
return 0;
}
}
item = arr[*pfront];
item = arr[*prear];
arr[*pfront] = 0;
arr[*prear] = 0;
(*prear)--;
if (*pfront == *prear)
if (*prear == -1)
*pfront = *prear = -1;
*pfront = -1;
else
return item;
(*pfront)++;
}
return item;
}
deQueue Code Implementation in C
void display(int *arr) {
int count(int *arr) {
int i;
int c = 0, i;
OUTPUT : front: 5 10 15 20 25 30 0 0 0
0 :rear
2
35
40
front: 5 10 15 20 25 30 35 40 0
0 :rear
Elements in the deQueue after insertion
and deletion:
front: 0 10 15 20 25 30 35 0 0
0 :rear