queue
Summary
Queue
- first in first out(FIFO)
Circular array implementation - arrays
| Operation | Method | Performance |
|---|---|---|
enqueue(v) | add after tail | - |
dequeue() | remove from head | - |
peek() | get head | - |
array “wraps” around to avoid having to shift all the elements during insertion/removal
Two stacks implementation
- enqueue to the bottom or dequeue from the bottom
| Operation | Method | Performance |
|---|---|---|
enqueue(v) | Expensive enqueue: pop items in stack1 to stack2, push v to bottom of stack1, push rest of elements back to stack1Push: push v to stack1 | - - |
dequeue() | Pop: pop v from stack1Expensive dequeue: pop items in stack1 to stack2, pop v from top of stack 2, push rest of elements back to stack2 | - - |
peek() | similar to dequeue | - - |
SLL implementation
| Operation | Method | Performance |
|---|---|---|
enqueue(v) | insert at tail | - |
dequeue() | remove from head | - |
peek() | get head | - |
Concept
Queue ADT operations
enqueue(v)- add
vto the back of the queue
- add
dequeue()- get the first item in the queue and remove it
peek()- get the first item in the queue without removing it
Monotonic queue
TODO