Stack: Class 12 PYQs 2024–2026 with solutions
All 3 CBSE board questions asked from Stack in 3 board papers, with the year, set and marks of each. 2 are solved free below. The Class 12 Computer Science PYQ Book: Solved Board Papers 2024-2026 (CBSE) has every solution, all chapters and 3 full board papers.
Stack: board weightage
Board weightage 2024–2026
| Year | 2024 | 2025 | 2026 |
|---|---|---|---|
| Questions | 1 | 1 | 1 |
| Marks | 3 | 3 | 3 |
Most asked topics
3 questions from 3 papers. Repeated questions are shown once with every year they were asked.
Jump to: 3 marks
3 marks: short answer
(a) FruitStack holds dictionaries {'Name', 'Origin', 'Price', 'Expiry'}. Write (i) push_fruit(FruitStack, Fruit): push if Price < 100; (ii) pop_fruit(FruitStack): pop and return, or display "UNDERFLOW"; (iii) display(FruitStack): from the top, or 'EMPTY STACK'.
OR (b) OR: accept 10 integers; push three-digit even ones; then pop all and display. Input 12, 31, 320, 457, 6, 92, 924, 220, 1, 218 → output 218 220 924 320.
Solution
def push_fruit(FruitStack, Fruit):
if Fruit['Price'] < 100:
FruitStack.append(Fruit)
def pop_fruit(FruitStack):
if FruitStack == []:
print('UNDERFLOW')
else:
return FruitStack.pop()
def display(FruitStack):
if FruitStack == []:
print('EMPTY STACK')
else:
for ele in FruitStack[::-1]:
print(ele)
OR
Stack = []
for C in range(10):
Num = int(input("Integer: "))
if 100 <= Num <= 999 and Num % 2 == 0:
Stack.append(Num)
while Stack:
print(Stack.pop(), end=' ')
218 220 924 320
(a) ClrStack holds records (ColorName, RED, GREEN, BLUE), e.g. ('Yellow', 237, 250, 68). Write (i) push_Clr(ClrStack, new_Clr) (ii) pop_Clr(ClrStack): pop and return the top record, or display "Underflow" (iii) isEmpty(ClrStack): return True if empty, else False.
OR (b) OR: (i) push_trail(N, myStack): push the last 5 elements of list N ([1..7] → stack [3,4,5,6,7]); (ii) pop_one(myStack): pop and return an element, or display 'Stack Underflow' and return None; (iii) display_all(myStack): display all elements without deleting, or 'Empty Stack'.
Solution
def push_Clr(ClrStack, new_Clr):
ClrStack.append(new_Clr)
def pop_Clr(ClrStack):
if len(ClrStack) == 0:
print("Underflow")
else:
return ClrStack.pop()
def isEmpty(ClrStack):
if len(ClrStack) == 0:
return True
else:
return False
OR
def push_trail(N, myStack):
for i in range(-5, 0):
myStack.append(N[i])
def pop_one(myStack):
if not myStack:
print('Stack Underflow')
return None
return myStack.pop()
def display_all(myStack):
if not myStack:
print('Empty Stack')
else:
for i in myStack[::-1]:
print(i, end=' ')
List Nums has random integers. Write (i) PushBig(): push all numbers with 5 or more digits from Nums onto stack BigNums; (ii) PopBig(): pop and display the numbers, then display "Stack Empty". Nums = [213, 10025, 167, 254923, 14, 1297653, 31498, 386, 92765].
Get every solution for all chapters
- Every board question of every chapter, each fully solved the way the board gives marks
- 3 complete board papers, each followed by its solutions
- Weightage and most-asked topics for every chapter
- Instant PDF download, colour and black & white print copies
Revising the chapter first? Complete Computer Science Notes for Class 12 (CBSE 083, 2026-27) →
What you get in the pack
- CBSE Class 12 Computer Science board papers 2024 to 2026 (3 full board papers)
- All 14 chapters and 3 board papers complete
- Part A: all 14 chapters, questions sorted chapter-wise and by marks
- Year-wise weightage table and most-asked topics for every chapter
- Part B: each full board paper followed by its complete solutions
- Full programs; every output traced and verified by running the code
- Only the current syllabus in Part A
All chapters in this pack
- PYQ Ch 1 Python Revision Tour
- PYQ Ch 2 Functions
- PYQ Ch 3 Exception Handling
- PYQ Ch 4 Text Files
- PYQ Ch 5 Binary Files
- PYQ Ch 6 CSV Files
- PYQ Ch 7 Stack
- PYQ Ch 8 Computer Networks I: Evolution and Data Communication
- PYQ Ch 9 Computer Networks II: Devices, Topologies and Types
- PYQ Ch 10 Network Protocols and Web Services
- PYQ Ch 11 Database Concepts
- PYQ Ch 12 SQL: DDL, DML and Queries
- PYQ Ch 13 SQL: Aggregates, Grouping and Joins
- PYQ Ch 14 Interface of Python with MySQL
- Board Paper 2026 Set 91 with Solutions
- Board Paper 2025 Set 91 with Solutions
- Board Paper 2024 Set 91 with Solutions
