Stack operations: Class 12 practice
A stack is last-in, first-out (LIFO): push adds to the top and pop removes the top. The quick answer and an example come first; then the method, worked examples and six graded questions.
Stack operations: quick answer
A stack is last-in, first-out (LIFO): push adds to the top and pop removes the top. In Python a list works as a stack with append() and pop().
Example: Starting with an empty stack, perform: push(19), push(59), push(7), push(5), push(65), push(21). What values are popped and what is the final stack (bottom → top)? Answer: Popped none; final [19, 59, 7, 5, 65, 21].
- Where it is taught: "Data Structures", Class 12 Computer Science.
- On this page: the method, 3 worked examples and 6 graded questions with a full answer key.
How to use this page (about 30 minutes)
- Read the method once, then cover the worked examples and try them yourself before reading the steps.
- Do the two Basic questions without notes. If either is wrong, re-read the matching worked example.
- Do the Standard and Challenge questions, then check every line of working against the answer key — not only the final answer.
- Write down the mistake behind each wrong answer and redo that question the next day.
What you should know first
- Python lists
The idea behind stack operations
A stack is last-in, first-out (LIFO): push adds to the top and pop removes the top. In Python a list works as a stack with append() and pop().
Step-by-step method
- Start with the given stack (top at the right).
- Apply each operation in order.
- Record popped values and the final stack.
Worked example 1 (Basic)
Starting with an empty stack, perform: push(19), push(59), push(7), push(5), push(65), push(21). What values are popped and what is the final stack (bottom → top)?
- Popped: none
- Final: [19, 59, 7, 5, 65, 21]
- Answer: Popped none; final [19, 59, 7, 5, 65, 21]
Worked example 2 (Standard)
Starting with an empty stack, perform: push(54), push(7), pop(), pop(), push(5), push(44), push(22), push(30). What values are popped and what is the final stack (bottom → top)?
- Popped: 7, 54
- Final: [5, 44, 22, 30]
- Answer: Popped 7, 54; final [5, 44, 22, 30]
Worked example 3 (Challenge)
Starting with an empty stack, perform: push(3), push(98), pop(), push(58), pop(), push(24), push(7), push(94), pop(), push(83). What values are popped and what is the final stack (bottom → top)?
- Popped: 98, 58, 94
- Final: [3, 24, 7, 83]
- Answer: Popped 98, 58, 94; final [3, 24, 7, 83]
Common mistakes and misconceptions
- Popping from the bottom
- Confusing a stack with a queue
Practice questions
- (Basic) Starting with an empty stack, perform: push(22), pop(), push(62), push(60), push(12), pop(). What values are popped and what is the final stack (bottom → top)?
- (Basic) Starting with an empty stack, perform: push(93), pop(), push(46), push(55), push(56), pop(). What values are popped and what is the final stack (bottom → top)?
- (Standard) Starting with an empty stack, perform: push(88), push(79), push(9), push(96), push(72), pop(), push(33), push(61). What values are popped and what is the final stack (bottom → top)?
- (Standard) Starting with an empty stack, perform: push(31), push(93), push(95), push(66), pop(), push(91), pop(), push(31). What values are popped and what is the final stack (bottom → top)?
- (Challenge) Starting with an empty stack, perform: push(57), push(9), pop(), pop(), push(69), push(62), push(89), pop(), push(58), push(87). What values are popped and what is the final stack (bottom → top)?
- (Challenge) Starting with an empty stack, perform: push(71), push(88), pop(), push(38), pop(), pop(), push(16), push(88), pop(), pop(). What values are popped and what is the final stack (bottom → top)?
Answer key with full working
- Q1: Popped: 22, 12 → Final: [62, 60] → Answer: Popped 22, 12; final [62, 60]
- Q2: Popped: 93, 56 → Final: [46, 55] → Answer: Popped 93, 56; final [46, 55]
- Q3: Popped: 72 → Final: [88, 79, 9, 96, 33, 61] → Answer: Popped 72; final [88, 79, 9, 96, 33, 61]
- Q4: Popped: 66, 91 → Final: [31, 93, 95, 31] → Answer: Popped 66, 91; final [31, 93, 95, 31]
- Q5: Popped: 9, 57, 89 → Final: [69, 62, 58, 87] → Answer: Popped 9, 57, 89; final [69, 62, 58, 87]
- Q6: Popped: 88, 38, 71, 88, 16 → Final: [] → Answer: Popped 88, 38, 71, 88, 16; final []
Which textbook this practice follows
This skill is taught under "Data Structures" in Class 12 Computer Science. Check your own textbook's contents page — CBSE, ICSE/ISC and state boards order chapters differently.
Answers on this page are generated and automatically re-checked by a second, independent calculation. They have not been reviewed by a teacher — if you spot a problem, tell us on WhatsApp.
Still stuck after the answer key?
If the same step in stack operations keeps going wrong, a short live 1 on 1 class can find the exact gap. The first demo class is free; send the class, board and chapter on WhatsApp (+91 9379416374).
Related practice and notes
More Class 12 Computer Science practice
Continue with this syllabus
Frequently asked questions
Which chapter is stack operations in?
This skill is taught under "Data Structures" in Class 12 Computer Science. Check your own textbook's contents page — CBSE, ICSE/ISC and state boards order chapters differently.
Which question should I start with?
Start with the Basic questions. Move to Standard only when both Basic answers match the key with the same working; the Challenge questions combine this skill with earlier ones.
How were the answers checked?
Answers on this page are generated and automatically re-checked by a second, independent calculation. They have not been reviewed by a teacher — if you spot a problem, tell us on WhatsApp.
Is this only for CBSE?
The skill names follow NCERT/CBSE, but the method is the same for ICSE, state boards, IGCSE and IB. Only the chapter name and order differ.
Can I get live help with this topic?
Yes. RG's E-Learning teaches live 1 on 1 online classes; the first demo class is free and fees are shared after it.