All lessons

4. Stacks & Queues

Deques and circular queues

0 of 5 activities0%

Reading 1

Double-ended queue

Open

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

Open

A circular queue mainly helps

Fill in 3

Both ends

Open

A double-ended queue is called a

Try it 4

Both ends

Open

Push front and back.

main.cpp
Loading editor…
Output will appear here.

Assignment 5

Front and back

Open

Read n ints into a sequence. Print first and last separated by a space (n>=1).

main.cpp
Loading editor…