Overflow Check
Before adding, we check if the array is full (`rear == size - 1`). If it is, trying to enqueue causes an Overflow.
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Enqueue is the process of adding an element to a Queue. In a FIFO structure, additions always happen at the 'Rear' (or Back).
Before adding, we check if the array is full (`rear == size - 1`). If it is, trying to enqueue causes an Overflow.
We first increment the `rear` pointer to the next available empty slot, and then insert the new value at that index.
If the queue was completely empty (`front == -1`), adding the first element means we must also set `front = 0` so we can later dequeue it.