In the previous post, we introduced Queue and discussed array implementation. In this post, linked list implementation is discussed. The following two main operations must be implemented efficiently.
In a Queue data structure, we maintain two pointers, front and rear. The front points the first item of queue and rear points to last item.
enQueue() This operation adds a new node after rear and moves rear to the next node.
deQueue() This operation removes the front node and moves front to the next node.
Dequeued item is 30
Time Complexity: Time complexity of both operations enqueue() and dequeue() is O(1) as we only change few pointers in both operations. There is no loop in any of the operations.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
- Circular Queue | Set 2 (Circular Linked List Implementation)
- Implementation of Deque using doubly linked list
- Priority Queue using Linked List
- Recursively Reversing a linked list (A simple implementation)
- Priority Queue using doubly linked list
- Difference between a Static Queue and a Singly Linked List
- Array implementation of queue (Simple)
- Queue | Set 1 (Introduction and Array Implementation)
- Circular Queue | Set 1 (Introduction and Array Implementation)
- XOR Linked List - A Memory Efficient Doubly Linked List | Set 1
- Convert singly linked list into circular linked list
- Merge a linked list into another linked list at alternate positions
- XOR Linked List – A Memory Efficient Doubly Linked List | Set 2
- Check if a linked list is Circular Linked List
- Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes