All lessonsOpen Open Open Open Open
4. Stacks & Queues
Stacks
0 of 5 activities0%
Reading 1
Last in, first out
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
After push 1, push 2, pop — which value is removed?
Fill in 3
Acronym
Try it 4
Parentheses sketch
Stack of chars.
main.cpp
Loading editor…
Output will appear here.
Assignment 5
Stack max size
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…