github:arrayQueue.java.
Purpose:
reuse a fixed size array. —-> Tracking 2 variables frontIndex for deletion and rearIndex for insertion.
CheckPoint:
- array size > 0.
- isEmpty()
- Check rearIndex == frontIndex.
- Enqueue –> queue is full.
- Dequeue –> queue is empty.
Complexity Analysis:
Time complexity :
enqueue: O(1)
assign the value to array[rearIndex]
dequeue: O(1)
move frontIndex to next index.
Space complexity : O(n)
The result:
Exception checking: