Abstract
- Linear, basically Array or Linked List with limitation that we can only push new element in from the back and remove elements from the front, follow a first-in, first-out (FIFO) principle.
Time Complexity
- O(1) to offer() - push in an element
- O(1) to poll() - pop out an element
- O(1) to peek() - read the element that is the first to be pop out
Implementation
Implementation with Circular Array
- Circular Array
- Visual
- push() at the rear index
- pop() & peek() at the head index
Implementation with Single Linked List
- Visual
- push() from tail node
- pop() & peek() from the head node
- The difference in the 2 implementation is similar to Stack implementation comparison