Algorithm
Implementation of Linear Queue using Linked List:
- Create a structure for the queue node with two fields: data and next pointer.
- Initialize two pointers, front and rear, to NULL.
- For enqueue operation:
- Create a new node with the given data.
- If the queue is empty (i.e., front is NULL), set both front and rear to the new node.
- Otherwise, set the next pointer of the current rear to the new node and update rear to the new node.
- For dequeue operation:
- If the queue is empty (i.e., front is NULL), display an underflow message.
- Otherwise, store the data of the front node, update front to the next node, and free the memory of the dequeued node.
- If front becomes NULL, set rear to NULL as well.
- For display operation:
- If the queue is empty, display an appropriate message.
- Otherwise, traverse the queue from front to rear and display each node's data.
Note: This implementation dynamically allocates memory for each node, making it efficient for scenarios where the size of the queue is not fixed.