Stack and queue operations
Library examples place two values into a FIFO queue and remove the older value.
| Stack push / pop | One active end | Use for nested or deferred work |
| Queue enqueue / dequeue | Opposite ends | Use for layer-by-layer exploration |
| Deque | Both ends | Can retain useful extremum candidates |
| Ring buffer | Advance index modulo capacity | Track size or reserve a slot to distinguish full and empty |
Python
from collections import deque q = deque() q.append(3) q.append(9) first = q.popleft() # 3
C++
#include <queue>
int firstInLine() {
std::queue<int> q;
q.push(3); q.push(9);
int first = q.front(); q.pop(); return first;
}Java
static int firstInLine() {
java.util.ArrayDeque<Integer> q = new java.util.ArrayDeque<>();
q.addLast(3); q.addLast(9);
return q.removeFirst();
}