All lessons

4. Stacks & Queues

Stacks

0 of 5 activities0%

Reading 1

Last in, first out

Open

A stack supports push (add on top), pop (remove top), and peek/top (read top).

Implement with a vector/array (amortized O(1) ops) or a linked list.

Use cases: undo, matching parentheses, DFS, expression evaluation.

vector<int> st;
st.push_back(3);
st.push_back(5);
st.pop_back();
cout << st.back();

Check 2

Order

Open

After push 1, push 2, pop — which value is removed?

Fill in 3

Acronym

Open

Stack order is abbreviated

Try it 4

Parentheses sketch

Open

Stack of chars.

main.cpp
Loading editor…
Output will appear here.

Assignment 5

Stack max size

Open

Read n operations. Each is PUSH x or POP. Print the maximum size the stack reaches (after each op). Start empty.

main.cpp
Loading editor…