Queue

A collection that allows insertions at one end and removals from the other.

Pros Cons
Provides a way to keep a buffer of things in the received order Limited access to elements
Implementations
Python: deque

q = deque()
q.append(1);
q.append(2); // [1, 2]
q.append(3); // [1, 2, 3]

q.popleft(); // [2, 3]
q.popleft(); // [3]

C++: queue

std::queue q;
q.push(1);
q.push(2); // [1, 2]
q.push(3); // [1, 2, 3]

q.pop(); // [2, 3]
q.pop(); // [3]

Java: Queue

Queue<Integer> q = new LinkedList<>();
q.add(1);
q.add(2); // [1, 2]
q.add(3); // [1, 2, 3]

q.poll(); // [2, 3]
q.poll(); // [3]

Operations Worst Average
DeleteO(1)
InsertO(1)
SearchO(n)

Similar