SlideShare a Scribd company logo
STACKSTACK
Kalyani Neve
Asst.Prof.
GHRIBM,Jalgaon
Stack :
Stack is a list of elements in which an element may be inserted or
deleted only at one end, called the top of the stack.
Two operations mainly performed on stack:
a) Push is used to insert an element
b) Pop is used to delete an element.
Push
AAA
BBB
CCC
Stack operations :
1. Stack() creates a new stack that is empty. It needs no
parameters and returns an empty stack.
2. push(item) adds a new item to the top of the stack. It needs
the item and returns nothing.
3. pop() removes the top item from the stack. It needs no
parameters and returns the item. The stack is modified.
4. peek() returns the top item from the stack but does not
remove it. It needs no parameters. The stack is not
modified.
5. isEmpty() tests to see whether the stack is empty. It needs
no parameters and returns a boolean value.
6. size() returns the number of items on the stack. It needs no
parameters and returns an integer.
Static Representation of Stack :
Algorithms for Push and Pop Operations on Stack :
PUSH(S, TOP, X)
This procedure insert an element X to the top of a stack which
is represented by S containing N elements with a pointer TOP
denoting the top element in the stack.
1. [Check stack overflow?]
If TOP >= N then :
Print OVERFLOW, and Return
2. [Increment TOP]
Set TOP := TOP +1
3. [Insert ITEM in new TOP position.]
Set S[TOP] := ITEM
4. Return
POP(S, TOP, ITEM)
This procedure deletes the top element of S and assigns it to the
variable ITEM.
1. [Check for stack underflow?]
If TOP = 0 then:
Print UNDERFLOW, and Return
2. [Assign TOP element to stack]
Set ITEM := S[TOP]
3. [Decreases TOP]
Set TOP := TOP -1
4. Return
Dynamic Representation of Stack :
Linked Representation :
The linked presentation of stack, i.e. stack is implemented using
a SLL.
The nodes are divided into two parts:
1. INFO hold the element of the stack.
2. LINK hold pointers to the next element in the stack.
AAA BBB CCC
TOP
PUSH_LINKSTK(INFO, LINK, TOP, AVAIL, ITEM)
This procedure pushes an ITEM into a linked stack.
1. [Available stack?]
If AVAIL=NULL then
Write OVERFLOW, and Exit
2. [Remove first node from AVAIL list.]
Set New := AVAIL and AVAIL := LINK[AVAIL]
3. [Copies ITEM into new node]
Set INFO[NEW] := ITEM
4. [New node points to the original top node in the stack]
Set LINK[NEW] := TOP
5. [Reset TOP]
Set TOP := NEW
6. Exit
POP_LINKSTK(INFO, LINK, TOP, AVAIL, ITEM)
This procedure deletes the top element of a linked list and assigns
it to the variable ITEM.
1. [Stack has an item to be removed?]
If TOP = NULL then Write : UNDERFLOW & Exit
2. [Copies top element into ITEM]
Set ITEM := INFO[TOP]
3. [Remember the old value of TOP pointer in TEMP and reset
TOP to point to the next element in the stack]
Set TEMP := TOP and TOP := LINK[TOP]
4. [Return deleted node to the AVAIL list]
Set LINK[TEMP := AVAIL and AVAIL := TEMP
5. Exit
Applications of Stack :
There are two main applications of stack:
1. Infix to Postfix
2. Evaluation of Postfix Expression
3.
1. Infix to Postfix
Infix : The operator written in between the operands. Eg. A+B
Prefix : The notation in which the operator is written before the
operands, it is called Prefix. Eg. +AB
Postfix: The notation in which the operator is written after the
operands, it is called Postfix. Eg. AB+
Infix to Postfix: Algorithm
POLISH(Q, P)
Suppose Q is an arithmetic expression written in infix notation.
This algorithm finds the equivalent postfix expression P.
1. Push “(“ onto stack, and add “)” to the end of Q.
2. Scan Q from left to right and repeat steps 3 to 6 for each
element of Q until the STACK is empty:
3. If an operand is encountered, add it to P.
4. If a left parenthesis is encountered, push it onto STACK.
5. If an operator is encountered, then:
1. Repeatedly POP from STACK and add to P each
operator (on the top of STACK) which has the same
precedence as or higher precedence than operator.
2. Add operator to stack.
[End of If Structure]
6. If a right parenthesis is encountered, then :
1. Repeatedly POP from stack and add to P each
operator (on the top of stack) until a left
parenthesis is encountered.
2. Remove the left parenthesis. [Do not add to P.]
[End of If Structure]
[End of step 2 loop]
6. Exit
1. A+(B*C-(D/E^F)*G)*G
Symbol scanned STACK POSTFIX
A ( A
+ (+ A
( (+( A
B (+( AB
* (+(* AB
C (+(* ABC
- (+(- ABC*
( (+(-( ABC*
D (+(-( ABC*D
/ (+(-(/ ABC*D
E (+(-(/ ABC*DE
^ (+(-(/^ ABC*DE
F (+(-(/^ ABC*DEF
) (+(- ABC*DEF^/
* (+(-* ABC*DEF^/
G (+(-* ABC*DEF^/G
) (+ ABC*DEF^/G*-
* (+* ABC*DEF^/G*-
H (+* ABC*DEF^/G*-H
) ABC*DEF^/G*-H*+
2. (A+B) * C/D+E^F/G
3. A-N/(C*D^E)
4. A+B/C-D
2. Evaluating Postfix Notation
• Use a stack to evaluate an expression in postfix notation.
• The postfix expression to be evaluated is scanned from left
to right.
• Variables or constants are pushed onto the stack.
• When an operator is encountered, the indicated action is
performed using the top elements of the stack, and the result
replaces the operands on the stack.
Postfix expressions: Algorithm using stacks (cont.)
Algorithm for evaluating a postfix expression
WHILE more input items exist
{
If symb is an operand
then push (opndstk,symb)
else //symbol is an operator
{
Opnd1=pop(opndstk);
Opnd2=pop(opndnstk);
Value = result of applying symb to opnd1 & opnd2
Push(opndstk,value);
} //End of else
} // end while
Result = pop (opndstk);

More Related Content

What's hot

Stack and queue
Stack and queueStack and queue
Stack and queue
Shakila Mahjabin
 
Sorting & Linked Lists
Sorting & Linked ListsSorting & Linked Lists
Sorting & Linked Lists
J.T.A.JONES
 
Lect11 Sorting
Lect11 SortingLect11 Sorting
Lect11 Sortingryokollll
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
Vineeta Garg
 
Stacks, Queues, Deques
Stacks, Queues, DequesStacks, Queues, Deques
Stacks, Queues, Deques
A-Tech and Software Development
 
Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)
EngineerBabu
 
Mca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueMca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queue
Rai University
 
(Data Structure) Chapter11 searching & sorting
(Data Structure) Chapter11 searching & sorting(Data Structure) Chapter11 searching & sorting
(Data Structure) Chapter11 searching & sortingFadhil Ismail
 
Stack and its operations
Stack and its operationsStack and its operations
Stack and its operations
V.V.Vanniaperumal College for Women
 
Stacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti AroraStacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti Arora
kulachihansraj
 
Stack project
Stack projectStack project
Stack project
Amr Aboelgood
 
Lecture 7 data structures and algorithms
Lecture 7 data structures and algorithmsLecture 7 data structures and algorithms
Lecture 7 data structures and algorithmsAakash deep Singhal
 
Introduction To Stack
Introduction To StackIntroduction To Stack
Introduction To Stack
Education Front
 
Stacks and queue
Stacks and queueStacks and queue
Stacks and queueAmit Vats
 
Unit 5 linked list
Unit   5 linked listUnit   5 linked list
Unit 5 linked list
Dabbal Singh Mahara
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
Apurbo Datta
 
Stacks & Queues
Stacks & QueuesStacks & Queues
Stacks & Queuestech4us
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stackvaibhav2910
 

What's hot (20)

Stack and queue
Stack and queueStack and queue
Stack and queue
 
Sorting & Linked Lists
Sorting & Linked ListsSorting & Linked Lists
Sorting & Linked Lists
 
Lect11 Sorting
Lect11 SortingLect11 Sorting
Lect11 Sorting
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
 
Stacks, Queues, Deques
Stacks, Queues, DequesStacks, Queues, Deques
Stacks, Queues, Deques
 
Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)
 
Mca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueMca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queue
 
(Data Structure) Chapter11 searching & sorting
(Data Structure) Chapter11 searching & sorting(Data Structure) Chapter11 searching & sorting
(Data Structure) Chapter11 searching & sorting
 
Stack and its operations
Stack and its operationsStack and its operations
Stack and its operations
 
Stacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti AroraStacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti Arora
 
Stack
StackStack
Stack
 
Stack project
Stack projectStack project
Stack project
 
Lecture 7 data structures and algorithms
Lecture 7 data structures and algorithmsLecture 7 data structures and algorithms
Lecture 7 data structures and algorithms
 
Introduction To Stack
Introduction To StackIntroduction To Stack
Introduction To Stack
 
Stacks and queue
Stacks and queueStacks and queue
Stacks and queue
 
Unit 5 linked list
Unit   5 linked listUnit   5 linked list
Unit 5 linked list
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
 
Stacks & Queues
Stacks & QueuesStacks & Queues
Stacks & Queues
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
 
Sorting
SortingSorting
Sorting
 

Similar to Unit 3 stack

Lec5-Stack-bukc-28022024-112316am (1) .pptx
Lec5-Stack-bukc-28022024-112316am (1) .pptxLec5-Stack-bukc-28022024-112316am (1) .pptx
Lec5-Stack-bukc-28022024-112316am (1) .pptx
haaamin01
 
Stacks in DATA STRUCTURE
Stacks in DATA STRUCTUREStacks in DATA STRUCTURE
Stacks in DATA STRUCTURE
Mandeep Singh
 
Data Structure and Algorithms Stacks
Data Structure and Algorithms StacksData Structure and Algorithms Stacks
Data Structure and Algorithms Stacks
ManishPrajapati78
 
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
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
nikshaikh786
 
Stack push pop
Stack push popStack push pop
Stack push pop
A. S. M. Shafi
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
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
 
Stack and its applications
Stack and its applicationsStack and its applications
Stack and its applications
Ahsan Mansiv
 
Stack Operation In Data Structure
Stack Operation In Data Structure Stack Operation In Data Structure
Stack Operation In Data Structure
DivyeshKumar Jagatiya
 
STACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureSTACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data Structure
Yaksh Jethva
 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacks
maamir farooq
 
Stack_Overview_Implementation_WithVode.pptx
Stack_Overview_Implementation_WithVode.pptxStack_Overview_Implementation_WithVode.pptx
Stack_Overview_Implementation_WithVode.pptx
chandankumar364348
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
AliRaza899305
 
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptxSTACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
KALPANAC20
 
DS MOD2 (1) (1).pptx
DS MOD2 (1) (1).pptxDS MOD2 (1) (1).pptx
DS MOD2 (1) (1).pptx
kumarkaushal17
 
Data structure and algorithm.(dsa)
Data structure and algorithm.(dsa)Data structure and algorithm.(dsa)
Data structure and algorithm.(dsa)
mailmerk
 
Stack - Data Structure - Notes
Stack - Data Structure - NotesStack - Data Structure - Notes
Stack - Data Structure - Notes
Omprakash Chauhan
 
Stack
StackStack

Similar to Unit 3 stack (20)

Lec5-Stack-bukc-28022024-112316am (1) .pptx
Lec5-Stack-bukc-28022024-112316am (1) .pptxLec5-Stack-bukc-28022024-112316am (1) .pptx
Lec5-Stack-bukc-28022024-112316am (1) .pptx
 
Stacks in DATA STRUCTURE
Stacks in DATA STRUCTUREStacks in DATA STRUCTURE
Stacks in DATA STRUCTURE
 
Data Structure and Algorithms Stacks
Data Structure and Algorithms StacksData Structure and Algorithms Stacks
Data Structure and Algorithms Stacks
 
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
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
 
Stack push pop
Stack push popStack push pop
Stack push pop
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
 
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
 
Stack and its applications
Stack and its applicationsStack and its applications
Stack and its applications
 
Stack Operation In Data Structure
Stack Operation In Data Structure Stack Operation In Data Structure
Stack Operation In Data Structure
 
STACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureSTACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data Structure
 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacks
 
Stack_Overview_Implementation_WithVode.pptx
Stack_Overview_Implementation_WithVode.pptxStack_Overview_Implementation_WithVode.pptx
Stack_Overview_Implementation_WithVode.pptx
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
 
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptxSTACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
 
DS MOD2 (1) (1).pptx
DS MOD2 (1) (1).pptxDS MOD2 (1) (1).pptx
DS MOD2 (1) (1).pptx
 
Data structure and algorithm.(dsa)
Data structure and algorithm.(dsa)Data structure and algorithm.(dsa)
Data structure and algorithm.(dsa)
 
Stack - Data Structure - Notes
Stack - Data Structure - NotesStack - Data Structure - Notes
Stack - Data Structure - Notes
 
Stack
StackStack
Stack
 

More from kalyanineve

Sorting and searching
Sorting and searchingSorting and searching
Sorting and searching
kalyanineve
 
Unit 7 sorting
Unit 7   sortingUnit 7   sorting
Unit 7 sorting
kalyanineve
 
Unit 5 graphs minimum spanning trees
Unit 5   graphs minimum spanning treesUnit 5   graphs minimum spanning trees
Unit 5 graphs minimum spanning trees
kalyanineve
 
Unit 4 tree
Unit 4   treeUnit 4   tree
Unit 4 tree
kalyanineve
 
Unit 1 introduction to data structure
Unit 1   introduction to data structureUnit 1   introduction to data structure
Unit 1 introduction to data structure
kalyanineve
 
Linux command ppt
Linux command pptLinux command ppt
Linux command ppt
kalyanineve
 

More from kalyanineve (6)

Sorting and searching
Sorting and searchingSorting and searching
Sorting and searching
 
Unit 7 sorting
Unit 7   sortingUnit 7   sorting
Unit 7 sorting
 
Unit 5 graphs minimum spanning trees
Unit 5   graphs minimum spanning treesUnit 5   graphs minimum spanning trees
Unit 5 graphs minimum spanning trees
 
Unit 4 tree
Unit 4   treeUnit 4   tree
Unit 4 tree
 
Unit 1 introduction to data structure
Unit 1   introduction to data structureUnit 1   introduction to data structure
Unit 1 introduction to data structure
 
Linux command ppt
Linux command pptLinux command ppt
Linux command ppt
 

Recently uploaded

Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
Kamal Acharya
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
abh.arya
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
MuhammadTufail242431
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
addressing modes in computer architecture
addressing modes  in computer architectureaddressing modes  in computer architecture
addressing modes in computer architecture
ShahidSultan24
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfCOLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
Kamal Acharya
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSETECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
DuvanRamosGarzon1
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 

Recently uploaded (20)

Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
addressing modes in computer architecture
addressing modes  in computer architectureaddressing modes  in computer architecture
addressing modes in computer architecture
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfCOLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSETECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 

Unit 3 stack

  • 2. Stack : Stack is a list of elements in which an element may be inserted or deleted only at one end, called the top of the stack. Two operations mainly performed on stack: a) Push is used to insert an element b) Pop is used to delete an element. Push AAA BBB CCC
  • 3. Stack operations : 1. Stack() creates a new stack that is empty. It needs no parameters and returns an empty stack. 2. push(item) adds a new item to the top of the stack. It needs the item and returns nothing. 3. pop() removes the top item from the stack. It needs no parameters and returns the item. The stack is modified. 4. peek() returns the top item from the stack but does not remove it. It needs no parameters. The stack is not modified.
  • 4. 5. isEmpty() tests to see whether the stack is empty. It needs no parameters and returns a boolean value. 6. size() returns the number of items on the stack. It needs no parameters and returns an integer. Static Representation of Stack : Algorithms for Push and Pop Operations on Stack :
  • 5. PUSH(S, TOP, X) This procedure insert an element X to the top of a stack which is represented by S containing N elements with a pointer TOP denoting the top element in the stack. 1. [Check stack overflow?] If TOP >= N then : Print OVERFLOW, and Return 2. [Increment TOP] Set TOP := TOP +1 3. [Insert ITEM in new TOP position.] Set S[TOP] := ITEM 4. Return
  • 6. POP(S, TOP, ITEM) This procedure deletes the top element of S and assigns it to the variable ITEM. 1. [Check for stack underflow?] If TOP = 0 then: Print UNDERFLOW, and Return 2. [Assign TOP element to stack] Set ITEM := S[TOP] 3. [Decreases TOP] Set TOP := TOP -1 4. Return
  • 7. Dynamic Representation of Stack : Linked Representation : The linked presentation of stack, i.e. stack is implemented using a SLL. The nodes are divided into two parts: 1. INFO hold the element of the stack. 2. LINK hold pointers to the next element in the stack. AAA BBB CCC TOP
  • 8. PUSH_LINKSTK(INFO, LINK, TOP, AVAIL, ITEM) This procedure pushes an ITEM into a linked stack. 1. [Available stack?] If AVAIL=NULL then Write OVERFLOW, and Exit 2. [Remove first node from AVAIL list.] Set New := AVAIL and AVAIL := LINK[AVAIL] 3. [Copies ITEM into new node] Set INFO[NEW] := ITEM 4. [New node points to the original top node in the stack] Set LINK[NEW] := TOP 5. [Reset TOP] Set TOP := NEW 6. Exit
  • 9. POP_LINKSTK(INFO, LINK, TOP, AVAIL, ITEM) This procedure deletes the top element of a linked list and assigns it to the variable ITEM. 1. [Stack has an item to be removed?] If TOP = NULL then Write : UNDERFLOW & Exit 2. [Copies top element into ITEM] Set ITEM := INFO[TOP] 3. [Remember the old value of TOP pointer in TEMP and reset TOP to point to the next element in the stack] Set TEMP := TOP and TOP := LINK[TOP] 4. [Return deleted node to the AVAIL list] Set LINK[TEMP := AVAIL and AVAIL := TEMP 5. Exit
  • 10. Applications of Stack : There are two main applications of stack: 1. Infix to Postfix 2. Evaluation of Postfix Expression 3.
  • 11. 1. Infix to Postfix Infix : The operator written in between the operands. Eg. A+B Prefix : The notation in which the operator is written before the operands, it is called Prefix. Eg. +AB Postfix: The notation in which the operator is written after the operands, it is called Postfix. Eg. AB+
  • 12. Infix to Postfix: Algorithm POLISH(Q, P) Suppose Q is an arithmetic expression written in infix notation. This algorithm finds the equivalent postfix expression P. 1. Push “(“ onto stack, and add “)” to the end of Q. 2. Scan Q from left to right and repeat steps 3 to 6 for each element of Q until the STACK is empty: 3. If an operand is encountered, add it to P. 4. If a left parenthesis is encountered, push it onto STACK. 5. If an operator is encountered, then: 1. Repeatedly POP from STACK and add to P each operator (on the top of STACK) which has the same precedence as or higher precedence than operator.
  • 13. 2. Add operator to stack. [End of If Structure] 6. If a right parenthesis is encountered, then : 1. Repeatedly POP from stack and add to P each operator (on the top of stack) until a left parenthesis is encountered. 2. Remove the left parenthesis. [Do not add to P.] [End of If Structure] [End of step 2 loop] 6. Exit
  • 14. 1. A+(B*C-(D/E^F)*G)*G Symbol scanned STACK POSTFIX A ( A + (+ A ( (+( A B (+( AB * (+(* AB C (+(* ABC - (+(- ABC* ( (+(-( ABC* D (+(-( ABC*D / (+(-(/ ABC*D E (+(-(/ ABC*DE
  • 15. ^ (+(-(/^ ABC*DE F (+(-(/^ ABC*DEF ) (+(- ABC*DEF^/ * (+(-* ABC*DEF^/ G (+(-* ABC*DEF^/G ) (+ ABC*DEF^/G*- * (+* ABC*DEF^/G*- H (+* ABC*DEF^/G*-H ) ABC*DEF^/G*-H*+
  • 16. 2. (A+B) * C/D+E^F/G 3. A-N/(C*D^E) 4. A+B/C-D
  • 17. 2. Evaluating Postfix Notation • Use a stack to evaluate an expression in postfix notation. • The postfix expression to be evaluated is scanned from left to right. • Variables or constants are pushed onto the stack. • When an operator is encountered, the indicated action is performed using the top elements of the stack, and the result replaces the operands on the stack.
  • 18. Postfix expressions: Algorithm using stacks (cont.)
  • 19. Algorithm for evaluating a postfix expression WHILE more input items exist { If symb is an operand then push (opndstk,symb) else //symbol is an operator { Opnd1=pop(opndstk); Opnd2=pop(opndnstk); Value = result of applying symb to opnd1 & opnd2 Push(opndstk,value); } //End of else } // end while Result = pop (opndstk);