QueueEasy

Front Operation

Queue Front / Peek Operation

Queue Front / Peek Operation

The Front (or Peek) operation allows you to retrieve or inspect the element at the front of the queue without removing it.

Key Rules

  1. Underflow Check: Before accessing the front element, verify if the queue is empty. In a linear queue, if front === -1 or front > rear, the queue contains no elements. Attempting to access the front element results in a Queue Underflow condition.
  2. Read Front Value: If elements exist, return queue[front]. Do NOT increment the front pointer. The queue remains unchanged.