Algorithm


Implementation of Linear Queue using Linked List:

  1. Create a structure for the queue node with two fields: data and next pointer.
  2. Initialize two pointers, front and rear, to NULL.
  3. For enqueue operation:
    1. Create a new node with the given data.
    2. If the queue is empty (i.e., front is NULL), set both front and rear to the new node.
    3. Otherwise, set the next pointer of the current rear to the new node and update rear to the new node.
  4. For dequeue operation:
    1. If the queue is empty (i.e., front is NULL), display an underflow message.
    2. Otherwise, store the data of the front node, update front to the next node, and free the memory of the dequeued node.
    3. If front becomes NULL, set rear to NULL as well.
  5. For display operation:
    1. If the queue is empty, display an appropriate message.
    2. 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.