[go: up one dir, main page]

0% found this document useful (0 votes)
29 views8 pages

Stack Data Structure PPT

Stack Data Structure About Stack Example for Stack Realtime uses

Uploaded by

Aachu Rachu
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)
29 views8 pages

Stack Data Structure PPT

Stack Data Structure About Stack Example for Stack Realtime uses

Uploaded by

Aachu Rachu
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/ 8

Stack Data Structure

LIFO (Last In, First Out) Principle


Your Name / Course
Introduction to Stack
• - A linear data structure
• - Works on LIFO principle
• - Last element inserted is the first removed
• - Analogy: Like a stack of plates
Stack Operations
• 1. Push(x): Insert element
• 2. Pop(): Remove top element
• 3. Peek/Top(): Show top element
• 4. isEmpty(): Checks if stack is empty
• 5. isFull(): Checks if stack is full
Stack Representation
• - Implemented using:
• • Array (fixed size)
• • Linked List (dynamic size)
• - TOP pointer keeps track of last element
Example: Push and Pop
• Push(10), Push(20), Push(30) → [10, 20, 30]
(Top=30)
• Pop() → removes 30 → [10, 20] (Top=20)
Applications of Stack
• - Undo/Redo in editors
• - Browser back/forward history
• - Expression evaluation
• - Function call stack
• - Balanced parentheses
Python Example
• stack = []

• stack.append(10)
• stack.append(20)
• stack.append(30)
• print('Stack:', stack)
• print('Popped:', stack.pop())
• print('After pop:', stack)
Conclusion
• - Stack is simple but powerful
• - Works on LIFO
• - Important in real-world applications

You might also like