Stack Data Structure
• Concepts, Operations & Code Examples
• Presented by: [Your Name]
What is a Stack?
• - A Stack is a linear data structure that follows
the LIFO (Last In, First Out) principle.
• - The element added last is the first to be
removed.
• - Think of a stack of plates — you add and
remove plates from the top.
Stack Operations
• 1. Push – Add an element to the top
• 2. Pop – Remove the top element
• 3. Peek / Top – View the top element
• 4. isEmpty – Check if the stack is empty
• 5. Size – Return the number of elements
Stack Use Cases
• - Function call management (call stack)
• - Undo functionality in editors
• - Balanced parentheses checker
• - Browser history tracking
Stack Implementation in Python
• class Stack:
• def __init__(self):
• [Link] = []
• def push(self, item):
• [Link](item)
•
• def pop(self):
• return [Link]() if not
Example Usage
• s = Stack()
• [Link](10)
• [Link](20)
• print([Link]()) # Output: 20
• print([Link]()) # Output: 10
• print(s.is_empty()) # Output: False
Summary
• - Stack = LIFO structure
• - Core operations: push, pop, peek
• - Widely used in programming problems and
applications