A circularly linked list is used to represent a Queue. A single variable p is used to access the Queue. To which node should p point such that both the operations enQueue and deQueue can be performed in constant time?
A
rear node
No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
not possible with a single pointer
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
C
node next to front
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
fornt node
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution
The correct option is B not possible with a single pointer
To add a new node:
new→ next = Rear → next;
Rear→ next = new;
Rear = new;
It will take constant time.
Similarly delete node from Front node will be:
Front = Rear → next;
Rear → next = Front → next;
free (Front);