SlideShare a Scribd company logo
Introduction to STACK
Ravi
presents ...
...
Stack
A stack is used to store elements where
the Last element In is the First one Out
(LIFO).
A common model of a stack is a plate or
coin stacker.
Plates are "pushed" onto to the top and
“pooped” off the top.
Stack
New elements are added or pushed onto
the top of the stack.
The first element to be removed or
popped is taken from the top - the last
one in.
Stack
Stack Operations
A stack is generally implemented with only two
principle operations
Push adds an item to a stack
Pop extracts the most recently pushed item from the
stack
Other methods such as
Top returns the item at the top without removing it
Isempty determines whether the stack has anything in it
Stack Implementation
Static Implementation (Using arrays)
Dynamic Implementation (Using dynamic
lists)
Stack Implementation
Using Arrays
For the static implementation of stack an
array will be used.
This array will hold the stack elements.
The top of a stack is represented by an
integer type variable which contains the
index of an array containing top element
of a stack.
Implementation of push operation on
stack
Void push(s,element)
1. If s Top=Max-1 print “Overflow stack” End If
 2. set s top=s top +1
 3. set s item[s top]=element
4. print “Element is pushed”
5. End
Stack Implementation
Using Arrays
4
3
2
1
0
Empty stack
StackSize = 5
top = -1
70
1
2
3
4
top
Push 7
70
81
2
3
4
top
Push 8 Push 9
70
81
92
3
4
top
Push 4
70
81
92
43
4
top
Push 5
70
81
92
43
54
top
top = StackSize – 1,
Stack is full,
We can’t push more elements.
Implementation of pop operation on
stack
int pop(s)
1. If s Top= -1 print “Underflow stack” return 0 and
goto step-5 End If
2. set popped=s item[s top]
3. set s top=s top -1
4. return popped
5. End
Stack Implementation Using Arrays
4
3
2
1
0
Empty stack
top = -1
We can’t pop mpre
elements
70
1
2
3
4
top
Pop
70
81
2
3
4
top
70
81
92
3
4
top
70
81
92
43
4
top
70
81
92
43
54
top
top = StackSize – 1,
Stack is full,
We can’t push more elements.
Pop
Pop
Pop Pop
THANK YOU

More Related Content

PPT
data structure, stack, stack data structure
PPTX
Stack operation
PDF
PPSX
Data Structure (Stack)
PPT
Lect 15-16 Zaheer Abbas
PPT
Stacks
PPTX
Stack converted
PPT
basics of queues
data structure, stack, stack data structure
Stack operation
Data Structure (Stack)
Lect 15-16 Zaheer Abbas
Stacks
Stack converted
basics of queues

What's hot (20)

PPT
Stacks overview with its applications
PPT
Difference between stack and queue
PPTX
Stack Data Structure
PPT
Queue AS an ADT (Abstract Data Type)
PPTX
Ds stack & queue
PPTX
Ds stacks
PPTX
Project of data structure
PPSX
Data structure stack&queue basics
PPT
stack and queue array implementation in java.
PPTX
Stack data structure
PPTX
Essential NumPy
PDF
STACK ( LIFO STRUCTURE) - Data Structure
PPT
Lecture 2d queues
PDF
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
PPTX
Introduction to stack
PPTX
Data Analysis packages
PPTX
Stack operation algorithms with example
PDF
Stack push pop
DOCX
Stack - Operations and Applications
PPTX
Stack and queue
Stacks overview with its applications
Difference between stack and queue
Stack Data Structure
Queue AS an ADT (Abstract Data Type)
Ds stack & queue
Ds stacks
Project of data structure
Data structure stack&queue basics
stack and queue array implementation in java.
Stack data structure
Essential NumPy
STACK ( LIFO STRUCTURE) - Data Structure
Lecture 2d queues
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
Introduction to stack
Data Analysis packages
Stack operation algorithms with example
Stack push pop
Stack - Operations and Applications
Stack and queue
Ad

Similar to Introduction to stack (20)

PPTX
Stack PPT.pptx
PPT
stack, opeartions on stack, applications of stack
PPT
Stack data structures with definition and code
PDF
Chapter 5 Stack and Queue.pdf
PPTX
Abscddnddmdkwkkstack implementation.pptx
PPT
PPTX
stack coding.pptx
PPT
Lecture5
PPTX
Module 2 ppt.pptx
PPT
PPT
Data Structure Lecture 2
PPTX
Data structure Stack
PPTX
Lecture#5 - Stack ADT.pptx
PDF
XIICSSTACK_INTRODUCTION cs
PPTX
VCE Unit 03vv.pptx
PPTX
DS UNIT 2 PPT.pptx stack queue representations
PPTX
Stack & Queue
PPTX
DATA STRUCTURE - STACK
PPTX
Data Structure.pptx
PPTX
Data Structures Stack and Queue Data Structures
Stack PPT.pptx
stack, opeartions on stack, applications of stack
Stack data structures with definition and code
Chapter 5 Stack and Queue.pdf
Abscddnddmdkwkkstack implementation.pptx
stack coding.pptx
Lecture5
Module 2 ppt.pptx
Data Structure Lecture 2
Data structure Stack
Lecture#5 - Stack ADT.pptx
XIICSSTACK_INTRODUCTION cs
VCE Unit 03vv.pptx
DS UNIT 2 PPT.pptx stack queue representations
Stack & Queue
DATA STRUCTURE - STACK
Data Structure.pptx
Data Structures Stack and Queue Data Structures
Ad

Recently uploaded (20)

PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
PPT on Performance Review to get promotions
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
Current and future trends in Computer Vision.pptx
DOCX
573137875-Attendance-Management-System-original
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPT
Project quality management in manufacturing
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
Sustainable Sites - Green Building Construction
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PPTX
additive manufacturing of ss316l using mig welding
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPT
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Automation-in-Manufacturing-Chapter-Introduction.pdf
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPT on Performance Review to get promotions
CYBER-CRIMES AND SECURITY A guide to understanding
Current and future trends in Computer Vision.pptx
573137875-Attendance-Management-System-original
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Project quality management in manufacturing
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Internet of Things (IOT) - A guide to understanding
UNIT 4 Total Quality Management .pptx
Sustainable Sites - Green Building Construction
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
additive manufacturing of ss316l using mig welding
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf

Introduction to stack

  • 2. Stack A stack is used to store elements where the Last element In is the First one Out (LIFO). A common model of a stack is a plate or coin stacker. Plates are "pushed" onto to the top and “pooped” off the top.
  • 3. Stack New elements are added or pushed onto the top of the stack. The first element to be removed or popped is taken from the top - the last one in.
  • 5. Stack Operations A stack is generally implemented with only two principle operations Push adds an item to a stack Pop extracts the most recently pushed item from the stack Other methods such as Top returns the item at the top without removing it Isempty determines whether the stack has anything in it
  • 6. Stack Implementation Static Implementation (Using arrays) Dynamic Implementation (Using dynamic lists)
  • 7. Stack Implementation Using Arrays For the static implementation of stack an array will be used. This array will hold the stack elements. The top of a stack is represented by an integer type variable which contains the index of an array containing top element of a stack.
  • 8. Implementation of push operation on stack Void push(s,element) 1. If s Top=Max-1 print “Overflow stack” End If  2. set s top=s top +1  3. set s item[s top]=element 4. print “Element is pushed” 5. End
  • 9. Stack Implementation Using Arrays 4 3 2 1 0 Empty stack StackSize = 5 top = -1 70 1 2 3 4 top Push 7 70 81 2 3 4 top Push 8 Push 9 70 81 92 3 4 top Push 4 70 81 92 43 4 top Push 5 70 81 92 43 54 top top = StackSize – 1, Stack is full, We can’t push more elements.
  • 10. Implementation of pop operation on stack int pop(s) 1. If s Top= -1 print “Underflow stack” return 0 and goto step-5 End If 2. set popped=s item[s top] 3. set s top=s top -1 4. return popped 5. End
  • 11. Stack Implementation Using Arrays 4 3 2 1 0 Empty stack top = -1 We can’t pop mpre elements 70 1 2 3 4 top Pop 70 81 2 3 4 top 70 81 92 3 4 top 70 81 92 43 4 top 70 81 92 43 54 top top = StackSize – 1, Stack is full, We can’t push more elements. Pop Pop Pop Pop