SlideShare a Scribd company logo
By:
Divyesh Jagatiya
Hardik Gopani
Keshu Odedara
∗ Stacks are linear lists.
∗ All deletions and insertions occur at one
end of the stack known as the TOP.
∗ Data going into the stack first, leaves
out last.
∗ Stacks are also known as LIFO data
structures (Last-In, First-Out).
Quick Introduction
∗ PUSH – Adds an item to the top of a stack.
∗ POP – Removes an item from the top of the
stack and returns it to the user.
∗ PEEP – Find an item from the top of the
stack.
∗ Change(Update) – User can change the
contents of the specific element.
Basic Stack Operations
∗ Reversing Data: We can use stacks to reverse data.
(example: files, strings)
Very useful for finding palindromes.
Consider the following pseudo code:
1) read (data)
2) loop (data not EOF and stack not full)
1) push (data)
2) read (data)
3) Loop (while stack not Empty)
1) pop (data)
2) print (data)
Stack Applications
∗ Converting Decimal to Binary: Consider the following code
1) Read (number)
2) Loop (number > 0)
1) digit = number modulo 2
2) print (digit)
3) number = number / 2
// from Data Structures by Gilbert and Frozen
The problem with this code is that it will print the binary
number backwards. (ex: 19 becomes 11001000 instead of 00010011. )
To remedy this problem, instead of printing the digit right away, we can
push it onto the stack. Then after the number is done being converted, we
pop the digit out of the stack and print it.
Stack Applications
∗ Evaluating arithmetic expressions.
∗ Prefix: + a b
∗ Infix: a + b (what we use in grammar school)
∗ Postfix: a b +
∗ In high level languages, infix notation cannot be used
to evaluate expressions. We must analyze the
expression to determine the order in which we
evaluate it. A common technique is to convert a infix
notation into postfix notation, then evaluating it.
Stack Applications
PUSH
OPERATI ON
PUSH Algorithm
PUSH(S, Top, x)
Step 1: [Check For Stack Overflow]
if Top >= N
then write("Stack Overflow")
Exit
Step 2: [Increment Top pointer By
Value One]
Top  Top +1
Step 3: [Perform Insertion]
s[Top]  X
Step 4: [Finished]
Exit
N 
Top 0
PUSH Algorithm
PUSH(S, Top, x)
Step 1: [Check For Stack Overflow]
if Top >= N
then write("Stack Overflow")
Exit
Step 2: [Increment Top pointer By
Value One]
Top  Top +1
Step 3: [Perform Insertion]
s[Top]  X
Step 4: [Finished]
Exit
N 
Top  A
PUSH Algorithm
PUSH(S, Top, x)
Step 1: [Check For Stack Overflow]
if Top >= N
then write("Stack Overflow")
Exit
Step 2: [Increment Top pointer By
Value One]
Top  Top +1
Step 3: [Perform Insertion]
s[Top]  X
Step 4: [Finished]
Exit
N 
Top 
A
B
PUSH Algorithm
PUSH(S, Top, x)
Step 1: [Check For Stack Overflow]
if Top >= N
then write("Stack Overflow")
Exit
Step 2: [Increment Top pointer By
Value One]
Top  Top +1
Step 3: [Perform Insertion]
s[Top]  X
Step 4: [Finished]
Exit
N 
A
B
Top  C
PUSH Algorithm
PUSH(S, Top, x)
Step 1: [Check For Stack Overflow]
if Top >= N
then write("Stack Overflow")
Exit
Step 2: [Increment Top pointer By
Value One]
Top  Top +1
Step 3: [Perform Insertion]
s[Top]  X
Step 4: [Finished]
Exit
N 
Top 
A
B
C
D
PUSH Algorithm
PUSH(S, Top, x)
Step 1: [Check For Stack Overflow]
if Top >= N
then write("Stack Overflow")
Exit
Step 2: [Increment Top pointer By
Value One]
Top  Top +1
Step 3: [Perform Insertion]
s[Top]  X
Step 4: [Finished]
Exit
N 
Top 
A
B
C
D
Stack Overflow
Pop
OPERATI ON
POP Algorithm
N 
Top 
A
B
C
D
POP(S , Top)
Step 1: [Check For Stack Underflow Or
Check Whether Stack Is Empty]
if (Top = 0) OR (Top = -1)
then write("Stack Underflow")
Exit
Step 2: [Decrement Top pointer /
Remove The Top Information]
Value  S[Top]
Top  Top - 1
Step 3: [Return From Top Element Of The
Stack]
Write(value)
Step 4: [Finished]
Exit
POP Algorithm
N 
A
B
C
POP(S , Top)
Step 1: [Check For Stack Underflow Or
Check Whether Stack Is Empty]
if (Top = 0) OR (Top = -1)
then write("Stack Underflow")
Exit
Step 2: [Decrement Top pointer /
Remove The Top Information]
Value  S[Top]
Top  Top - 1
Step 3: [Return From Top Element Of The
Stack]
Write(value)
Step 4: [Finished]
Exit
Top 
POP Algorithm
N 
A
B
POP(S , Top)
Step 1: [Check For Stack Underflow Or
Check Whether Stack Is Empty]
if (Top = 0) OR (Top = -1)
then write("Stack Underflow")
Exit
Step 2: [Decrement Top pointer /
Remove The Top Information]
Value  S[Top]
Top  Top - 1
Step 3: [Return From Top Element Of The
Stack]
Write(value)
Step 4: [Finished]
Exit
Top 
POP Algorithm
N 
A
POP(S , Top)
Step 1: [Check For Stack Underflow Or
Check Whether Stack Is Empty]
if (Top = 0) OR (Top = -1)
then write("Stack Underflow")
Exit
Step 2: [Decrement Top pointer /
Remove The Top Information]
Value  S[Top]
Top  Top - 1
Step 3: [Return From Top Element Of The
Stack]
Write(value)
Step 4: [Finished]
Exit
Top 
POP Algorithm
N 
POP(S , Top)
Step 1: [Check For Stack Underflow Or
Check Whether Stack Is Empty]
if (Top = 0) OR (Top = -1)
then write("Stack Underflow")
Exit
Step 2: [Decrement Top pointer /
Remove The Top Information]
Value  S[Top]
Top  Top - 1
Step 3: [Return From Top Element Of The
Stack]
Write(value)
Step 4: [Finished]
ExitTop  0
POP Algorithm
N 
POP(S , Top)
Step 1: [Check For Stack Underflow Or
Check Whether Stack Is Empty]
if (Top = 0) OR (Top = -1)
then write("Stack Underflow")
Exit
Step 2: [Decrement Top pointer /
Remove The Top Information]
Value  S[Top]
Top  Top - 1
Step 3: [Return From Top Element Of The
Stack]
Write(value)
Step 4: [Finished]
ExitTop  0
Stack Underflow
PEEP
OPERATI ON
PEEP Algorithm
N 
Top 
A
B
C
D
PEEP(S, Top, i)
Step 1: [Check For Stack Underflow]
if (Top - i + 1) <= 0
then write("Stack Underflow")
Exit
Step 2: [Return The ith Element From
The Top Of The Stack]
X  S(Top - i + 1)
Step 3: [Finished]
Exit
Top  D
CHANGE
OPERATI ON
CHANGE Algorithm
N 
Top 
A
B
C
D
CHANGE(S, Top, X, i)
Step 1: [Check For Stack Underflow]
if (Top - i + 1) < 0
then write("Stack Underflow")
Exit
Step 2: [Change The Element Value
From The Top Of The Stack]
S(Top - i + 1)  X
Step 3: [Finished]
Exit
CHANGE Algorithm
N 
Top 
A
B
C
D1
CHANGE(S, Top, X, i)
Step 1: [Check For Stack Underflow]
if (Top - i + 1) < 0
then write("Stack Underflow")
Exit
Step 2: [Change The Element Value
From The Top Of The Stack]
S(Top - i + 1)  X
Step 3: [Finished]
Exit
POLI SH
NOTATI ON
∗ Rules:
∗ Operands immediately go directly to output
∗ Operators are pushed into the stack (including parenthesis)
- Check to see if stack top operator is less than current operator
- If the top operator is less, than push the current operator onto stack
- If the top operator is greater than the current, pop top operator and push onto
stack, push current operator onto stack
- Priority 2: * /
- Priority 1: + -
- Priority 0: (
If we encounter a right parenthesis, pop from stack until we get
matching left parenthesis. Do not output parenthesis.
Infix to Postfix Conversion
A + B * C - D / E
Infix Stack Postfix
(
a)A ( A
b)+ (+ A
c)B (+ AB
d)* (+* AB
e)C (+* ABC
f)- (- ABC*+
g)D (- ABC*+D
h)/ (-/ ABC*+D
i)E (-/ ABC*+DE
j)) ABC*+DE/-
Infix to Postfix Example
A + B * C - D / E
Label No. Postfix Stack
1 A A
2 B A B
3 C A B C
4 * A B * C
5 + A + B * C
6 D A + B * C D
7 E A + B * C D E
8 / A + B * C D / E
9 - A + B * C – D / E
Postfix Evaluation

More Related Content

What's hot

Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
Janki Shah
 
Polish Notation In Data Structure
Polish Notation In Data StructurePolish Notation In Data Structure
Polish Notation In Data Structure
Meghaj Mallick
 
Stack using Array
Stack using ArrayStack using Array
Stack using Array
Sayantan Sur
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
Lemia Algmri
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
Vineeta Garg
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applications
Jsaddam Hussain
 
Binary search
Binary searchBinary search
Binary search
AparnaKumari31
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
vaibhav2910
 
Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structure
Sajid Marwat
 
stack presentation
stack presentationstack presentation
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
Gokul Hari
 
Heap sort
Heap sortHeap sort
Heap sort
Mohd Arif
 
Linked List
Linked ListLinked List
Linked List
Ashim Lamichhane
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
sandhya yadav
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
Adam Mukharil Bachtiar
 
Terminology of tree
Terminology of treeTerminology of tree
Terminology of tree
RacksaviR
 
Insertion sort algorithm power point presentation
Insertion  sort algorithm power point presentation Insertion  sort algorithm power point presentation
Insertion sort algorithm power point presentation
University of Science and Technology Chitttagong
 
Data Structures : hashing (1)
Data Structures : hashing (1)Data Structures : hashing (1)
Data Structures : hashing (1)
Home
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
Hossain Md Shakhawat
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
Apurbo Datta
 

What's hot (20)

Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
Polish Notation In Data Structure
Polish Notation In Data StructurePolish Notation In Data Structure
Polish Notation In Data Structure
 
Stack using Array
Stack using ArrayStack using Array
Stack using Array
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applications
 
Binary search
Binary searchBinary search
Binary search
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
 
Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structure
 
stack presentation
stack presentationstack presentation
stack presentation
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
 
Heap sort
Heap sortHeap sort
Heap sort
 
Linked List
Linked ListLinked List
Linked List
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
Terminology of tree
Terminology of treeTerminology of tree
Terminology of tree
 
Insertion sort algorithm power point presentation
Insertion  sort algorithm power point presentation Insertion  sort algorithm power point presentation
Insertion sort algorithm power point presentation
 
Data Structures : hashing (1)
Data Structures : hashing (1)Data Structures : hashing (1)
Data Structures : hashing (1)
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
 

Viewers also liked

Ch 8 introduction to data structures
Ch 8 introduction to data structuresCh 8 introduction to data structures
Ch 8 introduction to data structures
Chaffey College
 
Introductiont To Aray,Tree,Stack, Queue
Introductiont To Aray,Tree,Stack, QueueIntroductiont To Aray,Tree,Stack, Queue
Introductiont To Aray,Tree,Stack, Queue
Ghaffar Khan
 
Data Structure -List Stack Queue
Data Structure -List Stack QueueData Structure -List Stack Queue
Data Structure -List Stack Queue
surya pandian
 
Arrays Data Structure
Arrays Data StructureArrays Data Structure
Arrays Data Structure
student
 
Simple graph types
Simple graph typesSimple graph types
Simple graph types
Mahi Syama
 
Types of graphs
Types of graphsTypes of graphs
Types of graphs
abigail Dayrit
 
List Data Structure
List Data StructureList Data Structure
List Data Structure
Zidny Nafan
 

Viewers also liked (7)

Ch 8 introduction to data structures
Ch 8 introduction to data structuresCh 8 introduction to data structures
Ch 8 introduction to data structures
 
Introductiont To Aray,Tree,Stack, Queue
Introductiont To Aray,Tree,Stack, QueueIntroductiont To Aray,Tree,Stack, Queue
Introductiont To Aray,Tree,Stack, Queue
 
Data Structure -List Stack Queue
Data Structure -List Stack QueueData Structure -List Stack Queue
Data Structure -List Stack Queue
 
Arrays Data Structure
Arrays Data StructureArrays Data Structure
Arrays Data Structure
 
Simple graph types
Simple graph typesSimple graph types
Simple graph types
 
Types of graphs
Types of graphsTypes of graphs
Types of graphs
 
List Data Structure
List Data StructureList Data Structure
List Data Structure
 

Similar to Stack Operation In Data Structure

Stack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationStack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparation
RAtna29
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
nikshaikh786
 
Stack application
Stack applicationStack application
Stack application
Student
 
Stack_Overview_Implementation_WithVode.pptx
Stack_Overview_Implementation_WithVode.pptxStack_Overview_Implementation_WithVode.pptx
Stack_Overview_Implementation_WithVode.pptx
chandankumar364348
 
DS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptxDS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptx
prakashvs7
 
Unit 3 stack
Unit 3   stackUnit 3   stack
Unit 3 stack
kalyanineve
 
Stack in Data Structure
Stack in Data StructureStack in Data Structure
Stack in Data Structure
UshaP15
 
Stacks
StacksStacks
Stacks
sweta dargad
 
STACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureSTACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data Structure
Yaksh Jethva
 
Data structure lecture7
Data structure lecture7Data structure lecture7
Data structure lecture7
Kumar
 
Applicationofstack by Ali F.RAshid
Applicationofstack  by Ali F.RAshid Applicationofstack  by Ali F.RAshid
Applicationofstack by Ali F.RAshid
ali rashid
 
Application of Stack - Yadraj Meena
Application of Stack - Yadraj MeenaApplication of Stack - Yadraj Meena
Application of Stack - Yadraj Meena
Dipayan Sarkar
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
AliRaza899305
 
Stacks in DATA STRUCTURE
Stacks in DATA STRUCTUREStacks in DATA STRUCTURE
Stacks in DATA STRUCTURE
Mandeep Singh
 
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptx
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptxApplication of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptx
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptx
Prakash Zodge
 
Stacks
StacksStacks
Stacks
Sadaf Ismail
 
Data Structure and Algorithms Stacks
Data Structure and Algorithms StacksData Structure and Algorithms Stacks
Data Structure and Algorithms Stacks
ManishPrajapati78
 
Unit 3 stack
Unit   3 stackUnit   3 stack
Unit 3 stack
Dabbal Singh Mahara
 
Stack - Operations and Applications
Stack - Operations and ApplicationsStack - Operations and Applications
Stack - Operations and Applications
Sagacious IT Solution
 
Stack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADTStack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADT
Soumen Santra
 

Similar to Stack Operation In Data Structure (20)

Stack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationStack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparation
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
 
Stack application
Stack applicationStack application
Stack application
 
Stack_Overview_Implementation_WithVode.pptx
Stack_Overview_Implementation_WithVode.pptxStack_Overview_Implementation_WithVode.pptx
Stack_Overview_Implementation_WithVode.pptx
 
DS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptxDS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptx
 
Unit 3 stack
Unit 3   stackUnit 3   stack
Unit 3 stack
 
Stack in Data Structure
Stack in Data StructureStack in Data Structure
Stack in Data Structure
 
Stacks
StacksStacks
Stacks
 
STACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureSTACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data Structure
 
Data structure lecture7
Data structure lecture7Data structure lecture7
Data structure lecture7
 
Applicationofstack by Ali F.RAshid
Applicationofstack  by Ali F.RAshid Applicationofstack  by Ali F.RAshid
Applicationofstack by Ali F.RAshid
 
Application of Stack - Yadraj Meena
Application of Stack - Yadraj MeenaApplication of Stack - Yadraj Meena
Application of Stack - Yadraj Meena
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
 
Stacks in DATA STRUCTURE
Stacks in DATA STRUCTUREStacks in DATA STRUCTURE
Stacks in DATA STRUCTURE
 
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptx
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptxApplication of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptx
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptx
 
Stacks
StacksStacks
Stacks
 
Data Structure and Algorithms Stacks
Data Structure and Algorithms StacksData Structure and Algorithms Stacks
Data Structure and Algorithms Stacks
 
Unit 3 stack
Unit   3 stackUnit   3 stack
Unit 3 stack
 
Stack - Operations and Applications
Stack - Operations and ApplicationsStack - Operations and Applications
Stack - Operations and Applications
 
Stack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADTStack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADT
 

Recently uploaded

Recycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part IIRecycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part II
Aditya Rajan Patra
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
MIGUELANGEL966976
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
jpsjournal1
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
mamunhossenbd75
 
Casting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdfCasting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdf
zubairahmad848137
 
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
171ticu
 
Engine Lubrication performance System.pdf
Engine Lubrication performance System.pdfEngine Lubrication performance System.pdf
Engine Lubrication performance System.pdf
mamamaam477
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
KrishnaveniKrishnara1
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
wisnuprabawa3
 
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdfIron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
RadiNasr
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
171ticu
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEMTIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
HODECEDSIET
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 

Recently uploaded (20)

Recycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part IIRecycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part II
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
 
Casting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdfCasting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdf
 
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
 
Engine Lubrication performance System.pdf
Engine Lubrication performance System.pdfEngine Lubrication performance System.pdf
Engine Lubrication performance System.pdf
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
 
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdfIron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEMTIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 

Stack Operation In Data Structure

  • 2. ∗ Stacks are linear lists. ∗ All deletions and insertions occur at one end of the stack known as the TOP. ∗ Data going into the stack first, leaves out last. ∗ Stacks are also known as LIFO data structures (Last-In, First-Out). Quick Introduction
  • 3. ∗ PUSH – Adds an item to the top of a stack. ∗ POP – Removes an item from the top of the stack and returns it to the user. ∗ PEEP – Find an item from the top of the stack. ∗ Change(Update) – User can change the contents of the specific element. Basic Stack Operations
  • 4. ∗ Reversing Data: We can use stacks to reverse data. (example: files, strings) Very useful for finding palindromes. Consider the following pseudo code: 1) read (data) 2) loop (data not EOF and stack not full) 1) push (data) 2) read (data) 3) Loop (while stack not Empty) 1) pop (data) 2) print (data) Stack Applications
  • 5. ∗ Converting Decimal to Binary: Consider the following code 1) Read (number) 2) Loop (number > 0) 1) digit = number modulo 2 2) print (digit) 3) number = number / 2 // from Data Structures by Gilbert and Frozen The problem with this code is that it will print the binary number backwards. (ex: 19 becomes 11001000 instead of 00010011. ) To remedy this problem, instead of printing the digit right away, we can push it onto the stack. Then after the number is done being converted, we pop the digit out of the stack and print it. Stack Applications
  • 6. ∗ Evaluating arithmetic expressions. ∗ Prefix: + a b ∗ Infix: a + b (what we use in grammar school) ∗ Postfix: a b + ∗ In high level languages, infix notation cannot be used to evaluate expressions. We must analyze the expression to determine the order in which we evaluate it. A common technique is to convert a infix notation into postfix notation, then evaluating it. Stack Applications
  • 8. PUSH Algorithm PUSH(S, Top, x) Step 1: [Check For Stack Overflow] if Top >= N then write("Stack Overflow") Exit Step 2: [Increment Top pointer By Value One] Top  Top +1 Step 3: [Perform Insertion] s[Top]  X Step 4: [Finished] Exit N  Top 0
  • 9. PUSH Algorithm PUSH(S, Top, x) Step 1: [Check For Stack Overflow] if Top >= N then write("Stack Overflow") Exit Step 2: [Increment Top pointer By Value One] Top  Top +1 Step 3: [Perform Insertion] s[Top]  X Step 4: [Finished] Exit N  Top  A
  • 10. PUSH Algorithm PUSH(S, Top, x) Step 1: [Check For Stack Overflow] if Top >= N then write("Stack Overflow") Exit Step 2: [Increment Top pointer By Value One] Top  Top +1 Step 3: [Perform Insertion] s[Top]  X Step 4: [Finished] Exit N  Top  A B
  • 11. PUSH Algorithm PUSH(S, Top, x) Step 1: [Check For Stack Overflow] if Top >= N then write("Stack Overflow") Exit Step 2: [Increment Top pointer By Value One] Top  Top +1 Step 3: [Perform Insertion] s[Top]  X Step 4: [Finished] Exit N  A B Top  C
  • 12. PUSH Algorithm PUSH(S, Top, x) Step 1: [Check For Stack Overflow] if Top >= N then write("Stack Overflow") Exit Step 2: [Increment Top pointer By Value One] Top  Top +1 Step 3: [Perform Insertion] s[Top]  X Step 4: [Finished] Exit N  Top  A B C D
  • 13. PUSH Algorithm PUSH(S, Top, x) Step 1: [Check For Stack Overflow] if Top >= N then write("Stack Overflow") Exit Step 2: [Increment Top pointer By Value One] Top  Top +1 Step 3: [Perform Insertion] s[Top]  X Step 4: [Finished] Exit N  Top  A B C D Stack Overflow
  • 15. POP Algorithm N  Top  A B C D POP(S , Top) Step 1: [Check For Stack Underflow Or Check Whether Stack Is Empty] if (Top = 0) OR (Top = -1) then write("Stack Underflow") Exit Step 2: [Decrement Top pointer / Remove The Top Information] Value  S[Top] Top  Top - 1 Step 3: [Return From Top Element Of The Stack] Write(value) Step 4: [Finished] Exit
  • 16. POP Algorithm N  A B C POP(S , Top) Step 1: [Check For Stack Underflow Or Check Whether Stack Is Empty] if (Top = 0) OR (Top = -1) then write("Stack Underflow") Exit Step 2: [Decrement Top pointer / Remove The Top Information] Value  S[Top] Top  Top - 1 Step 3: [Return From Top Element Of The Stack] Write(value) Step 4: [Finished] Exit Top 
  • 17. POP Algorithm N  A B POP(S , Top) Step 1: [Check For Stack Underflow Or Check Whether Stack Is Empty] if (Top = 0) OR (Top = -1) then write("Stack Underflow") Exit Step 2: [Decrement Top pointer / Remove The Top Information] Value  S[Top] Top  Top - 1 Step 3: [Return From Top Element Of The Stack] Write(value) Step 4: [Finished] Exit Top 
  • 18. POP Algorithm N  A POP(S , Top) Step 1: [Check For Stack Underflow Or Check Whether Stack Is Empty] if (Top = 0) OR (Top = -1) then write("Stack Underflow") Exit Step 2: [Decrement Top pointer / Remove The Top Information] Value  S[Top] Top  Top - 1 Step 3: [Return From Top Element Of The Stack] Write(value) Step 4: [Finished] Exit Top 
  • 19. POP Algorithm N  POP(S , Top) Step 1: [Check For Stack Underflow Or Check Whether Stack Is Empty] if (Top = 0) OR (Top = -1) then write("Stack Underflow") Exit Step 2: [Decrement Top pointer / Remove The Top Information] Value  S[Top] Top  Top - 1 Step 3: [Return From Top Element Of The Stack] Write(value) Step 4: [Finished] ExitTop  0
  • 20. POP Algorithm N  POP(S , Top) Step 1: [Check For Stack Underflow Or Check Whether Stack Is Empty] if (Top = 0) OR (Top = -1) then write("Stack Underflow") Exit Step 2: [Decrement Top pointer / Remove The Top Information] Value  S[Top] Top  Top - 1 Step 3: [Return From Top Element Of The Stack] Write(value) Step 4: [Finished] ExitTop  0 Stack Underflow
  • 22. PEEP Algorithm N  Top  A B C D PEEP(S, Top, i) Step 1: [Check For Stack Underflow] if (Top - i + 1) <= 0 then write("Stack Underflow") Exit Step 2: [Return The ith Element From The Top Of The Stack] X  S(Top - i + 1) Step 3: [Finished] Exit Top  D
  • 24. CHANGE Algorithm N  Top  A B C D CHANGE(S, Top, X, i) Step 1: [Check For Stack Underflow] if (Top - i + 1) < 0 then write("Stack Underflow") Exit Step 2: [Change The Element Value From The Top Of The Stack] S(Top - i + 1)  X Step 3: [Finished] Exit
  • 25. CHANGE Algorithm N  Top  A B C D1 CHANGE(S, Top, X, i) Step 1: [Check For Stack Underflow] if (Top - i + 1) < 0 then write("Stack Underflow") Exit Step 2: [Change The Element Value From The Top Of The Stack] S(Top - i + 1)  X Step 3: [Finished] Exit
  • 27. ∗ Rules: ∗ Operands immediately go directly to output ∗ Operators are pushed into the stack (including parenthesis) - Check to see if stack top operator is less than current operator - If the top operator is less, than push the current operator onto stack - If the top operator is greater than the current, pop top operator and push onto stack, push current operator onto stack - Priority 2: * / - Priority 1: + - - Priority 0: ( If we encounter a right parenthesis, pop from stack until we get matching left parenthesis. Do not output parenthesis. Infix to Postfix Conversion
  • 28. A + B * C - D / E Infix Stack Postfix ( a)A ( A b)+ (+ A c)B (+ AB d)* (+* AB e)C (+* ABC f)- (- ABC*+ g)D (- ABC*+D h)/ (-/ ABC*+D i)E (-/ ABC*+DE j)) ABC*+DE/- Infix to Postfix Example
  • 29. A + B * C - D / E Label No. Postfix Stack 1 A A 2 B A B 3 C A B C 4 * A B * C 5 + A + B * C 6 D A + B * C D 7 E A + B * C D E 8 / A + B * C D / E 9 - A + B * C – D / E Postfix Evaluation