All lessonsOpen Open Open Open Open
4. Stacks & Queues
Deques and circular queues
0 of 5 activities0%
Reading 1
Double-ended queue
A deque allows push/pop at both front and back in O(1).
A circular queue uses a fixed array with head/tail modulo capacity so freed slots can be reused.
std::deque in C++ is a solid default deque.
deque<int> d;
d.push_front(1);
d.push_back(2);
d.pop_front();Check 2
Circular benefit
A circular queue mainly helps
Fill in 3
Both ends
Try it 4
Both ends
Push front and back.
main.cpp
Loading editor…
Output will appear here.
Assignment 5
Front and back
Read n ints into a sequence. Print first and last separated by a space (n>=1).
main.cpp
Loading editor…