Computer Science Class 12 –Stack Data Structure Notes (CBSE)

 Data Structure Stack Class 12 Notes


Welcome Dear Students!

    Are you preparing for your Class 12 CBSE Computer Science board exam? Then you're at the right place! On this page, you’ll get simple, easy-to-understand notes on the most important Data Structure – Stack chapter. Whether you're revising for your exam or trying to understand the basics, these notes will definitely help you score better!

 What’s Inside This Post?

  • Why Are Data Structures Important?
  • Data Type Vs Data Structure
  • What is a Data Type?
  • What is a Data Structure?
  • What is a Stack?
  • Implementation of stack using list
  • List methods used and Important things to remember 
  • Real-life Analogy:
  • Applications of Stack:
  • Program 
  •     1.Stack Initialization
  •     2.push() – Add an element to the stack
  •     3.pop() – Remove the top element from the stack
  •     4.peek() – View the top element without removing it
  •     5.isEmpty() – Check if the stack is empty
  •     6.isFull() – (Only for fixed size stacks) 
  • Stack Overflow:
  • Stack Underflow:


Sample 4-Mark Questions from Stack

Q1. Stack Push and Pop Functions

Write functions push(stack, element) and pop(stack) to perform push and pop operations on a stack implemented using a list in Python. Also, show example usage of both functions.

Hint: Use append() to push and pop() to remove the top element. Always check for underflow before popping.

Q2. Check for Stack Underflow

Write a Python function pop_stack(stack) which removes the top element from a stack. If the stack is empty, display “Underflow! Stack is empty.”

Hint: Use if not stack: before popping.

Q3. Display Stack Elements (Top to Bottom)

Write a Python function to display all elements of a stack from top to bottom. Assume the stack is implemented using a list.

 Hint: Use for i in range(len(stack)-1, -1, -1): to display from top.

 Q4. Stack Program to Check Palindrome

Write a Python function using stack logic to check whether a string is a palindrome or not (e.g., “madam”).

Hint: Push all characters into a stack and compare with the original string using pop.

Why Should You Focus on Stack?

  •  One of the most repeated board questions
  •  Code is short, logic is simple
  •  Easy to write and easy to score
  •  Expected in both theory and practical exam

 Need Help?

 I’ve shared detailed notes and example codes in the Stack Notes PDF below.

 Click Here to Download Stack Notes PDF

 Watch Stack Tutorial Video on YouTube

Post a Comment

0 Comments