Subtopic 5.1
Queue with an Array
5lessons24 min0done
A queue built on an array keeps its elements in a fixed-size array. The front index knows where the first element is and the rear index knows where the last one is. In an empty queue front is 0 and rear is -1.
Each operation is its own lesson: creating, enqueue, dequeue and peek. The last lesson shows the weak spot of this simple version: cells freed at the front by dequeue can never be used again.