is used to access the Queue. To which node should point such that both the operations enQueue and deQueue can be performed in time?
A circularly linked list is used to represent a queue as shown in the figure above. A single variable
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
The deQueue operation requires access to the Head node (to return to the caller) and access to the Rear node (to update the Rear node's pointer to point to the new Head node).
The enQueue operation requires access to the Rear node (to update to the Rear node's pointer to point to the new Rear node).
If Q points to the Rear node, access to the Rear node is O(1) (one step: dereferencing the Q pointer), access to the Head node is also O(1) (two steps: dereferencing the Q pointer and then dereferencing the Rear node's pointer to the Head node).