0% found this document useful (0 votes)
3 views

Stack Data Structure Presentation

A stack is a linear data structure that operates on the LIFO principle, where the last element added is the first to be removed. Key operations include push, pop, peek, isEmpty, and size, with common use cases in function call management, undo functionality, and browser history tracking. The document also provides a Python implementation and example usage of a stack.

Uploaded by

Maimoona Ghani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Stack Data Structure Presentation

A stack is a linear data structure that operates on the LIFO principle, where the last element added is the first to be removed. Key operations include push, pop, peek, isEmpty, and size, with common use cases in function call management, undo functionality, and browser history tracking. The document also provides a Python implementation and example usage of a stack.

Uploaded by

Maimoona Ghani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

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):
• self.items = []

• def push(self, item):


• self.items.append(item)

• def pop(self):
• return self.items.pop() if not
Example Usage
• s = Stack()
• s.push(10)
• s.push(20)
• print(s.pop()) # Output: 20
• print(s.peek()) # Output: 10
• print(s.is_empty()) # Output: False
Summary
• - Stack = LIFO structure
• - Core operations: push, pop, peek
• - Widely used in programming problems and
applications

You might also like