Algorithm


Implementation of Linear Queue using Array:

  1. Initialize the queue with a fixed size and set front and rear to -1.
  2. To enqueue an element:
    1. Check if the queue is full (i.e., rear == size - 1).
    2. If full, display an overflow message and exit.
    3. If not, increment rear and insert the element at queue[rear].
  3. To dequeue an element:
    1. Check if the queue is empty (i.e., front == rear).
    2. If empty, display an underflow message and exit.
    3. If not, increment front and retrieve the element at queue[front].
  4. To display the queue:
    1. Check if the queue is empty (i.e., front == rear).
    2. If empty, display a message indicating the queue is empty.
    3. If not, iterate from front + 1 to rear and display the elements.

    Note: Linear queues do not reuse space of dequeued elements, leading to inefficiency. Circular queues address this limitation.