0% found this document useful (0 votes)
18 views12 pages

Stack Representation in Data Structures

Uploaded by

Bhagyashree
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)
18 views12 pages

Stack Representation in Data Structures

Uploaded by

Bhagyashree
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

Stack in Data Structures

• Concepts, Operations, and Applications

• Presented by: [Your Name]


• Department: [Your Department/College
Name]
Introduction to Stack
• • A Stack is a linear data structure that follows
the LIFO (Last In First Out) principle.
• • The element inserted last is the first one to
be removed.
• • Example: Stack of plates – only the top plate
can be accessed.
Stack Representation
• • Represented using:
• - Array
• - Linked List
• • Has a top pointer that keeps track of the last
inserted element.
Basic Operations on Stack
• 1. Push – Insert an element into the stack
• 2. Pop – Remove the top element
• 3. Peek (Top) – View the top element
• 4. isEmpty() – Check if stack is empty
• 5. isFull() – Check if stack is full (for array)
LIFO Principle Illustration
• Example:
• Push(10) → Push(20) → Push(30)
• Stack: [10, 20, 30]
• Pop() → removes 30
• New Stack: [10, 20]
Stack Implementation using Array
(C Example)
• #define MAX 5
• int stack[MAX];
• int top = -1;

• void push(int val) {


• if(top == MAX-1)
• printf("Stack Overflow");
• else
• stack[++top] = val;
Stack Implementation using Linked
List
• • Each node contains:
• - Data
• - Pointer to next node
• • Top points to the most recently inserted
node.
Applications of Stack
• • Expression Evaluation (Postfix, Prefix)
• • Expression Conversion (Infix → Postfix)
• • Function Call Management (Recursion)
• • Undo/Redo Operations
• • Backtracking Algorithms
• • Parenthesis Matching
Advantages and Limitations
• Advantages:
• • Simple implementation
• • Efficient for recursive problems

• Limitations:
• • Fixed size (array-based)
• • Access limited to top element only
Real-Life Examples
• • Browser Back Button
• • Call Stack in programming
• • Undo feature in text editors
Summary
• • Stack follows LIFO
• • Common operations: Push, Pop, Peek
• • Implemented via Array or Linked List
• • Used in expression evaluation, recursion,
and memory management
References
• • Data Structures by Seymour Lipschutz
• • GeeksforGeeks
• • TutorialsPoint
• • Programiz

You might also like