![]() |
VOOZH | about |
A Queue is a linear data structure that follows the First-In-First-Out (FIFO) principle. The element inserted first is the first one to be removed.
π Queue-Linked-List-Implementation_
It can be implemented using a linked list, where each element of the queue is represented as a node.
To implement a queue with a linked list, we maintain:
A Node structure/class that contains:
Two pointers/references:
The enqueue operation adds an element to the rear of the queue. Unlike array implementation, there is no fixed capacity in linked list. Overflow occurs only when memory is exhausted.
Time Complexity: O(1)
Auxiliary Space: O(1)
The dequeue operation removes an element from the front of the queue.
Time Complexity: O(1)
Auxiliary Space: O(1)
The isEmpty operation checks whether the queue has no elements.
Time Complexity: O(1)
Auxiliary Space: O(1)
The front() function returns the element at the front of the queue without removing it.
Time Complexity: O(1)
Auxiliary Space: O(1)
Dequeue: 10 Front: 20 Size: 2