SlideShare a Scribd company logo
Stack
Name:- Yaksh Jethva
Introduction about stack
A stack is a linear OR non-primitive list in which insertion and deletion operations are performed at only one end of the list.
A stack is Last in First out (LIFO) Structure.
A stack is a linear data structure in which elements are added and removed from one end, called top of stack.
For example of stack is, consider a stack of plates on the counter in cafeteria.
450 TOP
100
300
230
124 BOTTOM
Figure: Stack (vertical
representation of stack)
Operations on stack
The insertion operation is referred to as a PUSH operation and deletion operation is referred to as a POP operation.
The most accessible element in the stack is known as a TOP element and the least accessible element in the stack is known as a
BOTTOM element.
Since, the insertion and deletion operation are performed at only one end of the stack.
Stack operations are listed below:-
(1)Push: The operations that add an element to the top of the stack is called PUSH operation. It is used to insert an element
into the stack.
(2)Pop: The operation that delete top element from the top of stack is called POP. it is used to delete an element from stack
(3)Peep: it is used to retrieve ith element from the top of the stack.
Algorithm for PUSH Operation
In push operation, we can add elements to the top of the stack, so before push operation, user must check the stack, it should not be a
full.
If stack is already full and when we try to add the elements then error occurs. It is called “Stack Over Flow” error.
PUSH(S, TOP, VAL)
This algorithm insert an element X to the top of the stack.
The Stack is represented by vector S which contains N elements.
TOP is a pointer which points to the top element of the Stack.
1.[Check for stack overflow]
If TOP >= N then
Write (‘Stack Overflow’) Return
2.[Increment TOP]
TOP = TOP + 1
3.[Insert Element]
S [TOP] = VAL
4.[Finished]
Return
Algorithm for POP Operation
In POP operation, we can delete or remove an elements from top of the stack, so before pop operation, user must check the stack, stack
should not be a empty.
If the stack is empty, and we try to pop an element, then error occur. It is called “Stack under Flow” error.
POP(S, TOP)
➢This algorithm removes an element from the Top of the Stack.
➢The Stack is represented by vector S which contains N elements.
➢TOP is a pointer which points to the top element of the Stack.
1.[Check for the Underflow on the Stack]
If TOP = 0 then
Write (‘STACK UNDERFLOW’) Exit
2.[Decrement Pointer]
TOP = TOP - 1
3.[Return former top element of the stack]
Return(S [TOP + 1])
Algorithm of displaying in Stack
DISPLAY(top,i,a[i])
1.If top=0 then
Print ‘Stack is empty’
Exit
Else
2.For i=top to 0
Print a[i]
End for
3.Exit
Operation Performed on Stack
Application of Stack
● To reverse a word. You push a given word to stack - letter by letter - and then pop letters from the stack.
● An "undo" mechanism in text editors; this operation is accomplished by keeping all text changes in a stack.
○ Undo/Redo stacks in Excel or Word.
● Language processing :
○ compiler's syntax check for matching braces is implemented by using stack.
● A stack of plates/books in a cupboard.
● A garage that is only one car wide. To remove the first car in we have to take out all the other cars in after it.
● Expression Evolution
● Expression conversion
● Function Call
Evaluation of Expression
(2+(4-1)*3)
THANK YOU!!!

More Related Content

What's hot

Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)
Self-Employed
 
Stack
StackStack
Stack of Data structure
Stack of Data structureStack of Data structure
Stack of Data structure
Sheikh Monirul Hasan
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
anooppjoseph
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
Rabin BK
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
Stacks and Queue - Data Structures
Stacks and Queue - Data StructuresStacks and Queue - Data Structures
Stacks and Queue - Data Structures
Dr. Jasmine Beulah Gnanadurai
 
Stacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti AroraStacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti Arora
kulachihansraj
 
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 in DATA STRUCTURE
Stacks in DATA STRUCTUREStacks in DATA STRUCTURE
Stacks in DATA STRUCTURE
Mandeep Singh
 
Data structure using c++
Data structure using c++Data structure using c++
Data structure using c++
Prof. Dr. K. Adisesha
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Muhammad Hammad Waseem
 
Stack and queue
Stack and queueStack and queue
Stack and queue
Katang Isip
 
Heap sort
Heap sort Heap sort
stack and queue array implementation in java.
stack and queue array implementation in java.stack and queue array implementation in java.
stack and queue array implementation in java.
CIIT Atd.
 
Queue
QueueQueue
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
Meghaj Mallick
 
Stacks overview with its applications
Stacks overview with its applicationsStacks overview with its applications
Stacks overview with its applicationsSaqib Saeed
 

What's hot (20)

Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)
 
Stack
StackStack
Stack
 
Stack of Data structure
Stack of Data structureStack of Data structure
Stack of Data structure
 
Stack
StackStack
Stack
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
 
Stacks and Queue - Data Structures
Stacks and Queue - Data StructuresStacks and Queue - Data Structures
Stacks and Queue - Data Structures
 
Stacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti AroraStacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti Arora
 
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 in DATA STRUCTURE
Stacks in DATA STRUCTUREStacks in DATA STRUCTURE
Stacks in DATA STRUCTURE
 
Data structure using c++
Data structure using c++Data structure using c++
Data structure using c++
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Stack a Data Structure
Stack a Data StructureStack a Data Structure
Stack a Data Structure
 
Heap sort
Heap sort Heap sort
Heap sort
 
stack and queue array implementation in java.
stack and queue array implementation in java.stack and queue array implementation in java.
stack and queue array implementation in java.
 
Queue
QueueQueue
Queue
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
 
Stacks overview with its applications
Stacks overview with its applicationsStacks overview with its applications
Stacks overview with its applications
 

Similar to STACK ( LIFO STRUCTURE) - 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
 
Module 2 ppt.pptx
Module 2 ppt.pptxModule 2 ppt.pptx
Module 2 ppt.pptx
SonaPathak4
 
Stack PPT.pptx
Stack PPT.pptxStack PPT.pptx
Stack PPT.pptx
UzmaRizvi5
 
Stack data structure
Stack data structureStack data structure
Stack data structure
rogineojerio020496
 
Stack and its operations, Queue and its operations
Stack and its operations, Queue and its operationsStack and its operations, Queue and its operations
Stack and its operations, Queue and its operations
poongothai11
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
Vineeta Garg
 
Stack push pop
Stack push popStack push pop
Stack push pop
A. S. M. Shafi
 
Chapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdfChapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdf
GirT2
 
Stack and its operation implemented with array new - Copy.pptx
Stack and its operation implemented with array new - Copy.pptxStack and its operation implemented with array new - Copy.pptx
Stack and its operation implemented with array new - Copy.pptx
Shivam Kumar
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
EktaVaswani2
 
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-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptxDS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptx
prakashvs7
 
Data structure Stack
Data structure StackData structure Stack
Data structure Stack
Praveen Vishwakarma
 
DSA- Unit III- STACK AND QUEUE
DSA- Unit III- STACK AND QUEUEDSA- Unit III- STACK AND QUEUE
DSA- Unit III- STACK AND QUEUE
swathirajstar
 
Unit 3 stack
Unit   3 stackUnit   3 stack
Unit 3 stack
Dabbal Singh Mahara
 
DATA STRUCTURE - STACK
DATA STRUCTURE - STACKDATA STRUCTURE - STACK
DATA STRUCTURE - STACK
Devyani Chaudhari
 
04 stacks
04 stacks04 stacks
04 stacks
Rajan Gautam
 
Stack
StackStack

Similar to STACK ( LIFO STRUCTURE) - 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
 
Lect 15-16 Zaheer Abbas
Lect 15-16 Zaheer  AbbasLect 15-16 Zaheer  Abbas
Lect 15-16 Zaheer Abbas
 
Module 2 ppt.pptx
Module 2 ppt.pptxModule 2 ppt.pptx
Module 2 ppt.pptx
 
Stack PPT.pptx
Stack PPT.pptxStack PPT.pptx
Stack PPT.pptx
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
Stack and its operations, Queue and its operations
Stack and its operations, Queue and its operationsStack and its operations, Queue and its operations
Stack and its operations, Queue and its operations
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
 
Stack push pop
Stack push popStack push pop
Stack push pop
 
Chapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdfChapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdf
 
Stack and its operation implemented with array new - Copy.pptx
Stack and its operation implemented with array new - Copy.pptxStack and its operation implemented with array new - Copy.pptx
Stack and its operation implemented with array new - Copy.pptx
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
 
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-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptxDS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptx
 
Data structure Stack
Data structure StackData structure Stack
Data structure Stack
 
DSA- Unit III- STACK AND QUEUE
DSA- Unit III- STACK AND QUEUEDSA- Unit III- STACK AND QUEUE
DSA- Unit III- STACK AND QUEUE
 
Data structure by Digvijay
Data structure by DigvijayData structure by Digvijay
Data structure by Digvijay
 
Unit 3 stack
Unit   3 stackUnit   3 stack
Unit 3 stack
 
DATA STRUCTURE - STACK
DATA STRUCTURE - STACKDATA STRUCTURE - STACK
DATA STRUCTURE - STACK
 
04 stacks
04 stacks04 stacks
04 stacks
 
Stack
StackStack
Stack
 

More from Yaksh Jethva

Operator_Overloaing_Type_Conversion_OOPC(C++)
Operator_Overloaing_Type_Conversion_OOPC(C++)Operator_Overloaing_Type_Conversion_OOPC(C++)
Operator_Overloaing_Type_Conversion_OOPC(C++)
Yaksh Jethva
 
About Markets (Types of markets) - Economics
About Markets (Types of markets) - EconomicsAbout Markets (Types of markets) - Economics
About Markets (Types of markets) - Economics
Yaksh Jethva
 
Cost and Various Cost Types
Cost and Various Cost TypesCost and Various Cost Types
Cost and Various Cost Types
Yaksh Jethva
 
Logic Families ( Digital Electronics )
Logic Families ( Digital Electronics )Logic Families ( Digital Electronics )
Logic Families ( Digital Electronics )
Yaksh Jethva
 
ANSI-SPARC Architecture - (3-Tier Architecture)
ANSI-SPARC Architecture - (3-Tier Architecture)ANSI-SPARC Architecture - (3-Tier Architecture)
ANSI-SPARC Architecture - (3-Tier Architecture)
Yaksh Jethva
 
Transaction Properties(ACID Properties)
Transaction Properties(ACID Properties)Transaction Properties(ACID Properties)
Transaction Properties(ACID Properties)
Yaksh Jethva
 
AVL tree ( Balanced Binary Search Tree)-Data Structure
AVL tree ( Balanced Binary Search Tree)-Data StructureAVL tree ( Balanced Binary Search Tree)-Data Structure
AVL tree ( Balanced Binary Search Tree)-Data Structure
Yaksh Jethva
 

More from Yaksh Jethva (7)

Operator_Overloaing_Type_Conversion_OOPC(C++)
Operator_Overloaing_Type_Conversion_OOPC(C++)Operator_Overloaing_Type_Conversion_OOPC(C++)
Operator_Overloaing_Type_Conversion_OOPC(C++)
 
About Markets (Types of markets) - Economics
About Markets (Types of markets) - EconomicsAbout Markets (Types of markets) - Economics
About Markets (Types of markets) - Economics
 
Cost and Various Cost Types
Cost and Various Cost TypesCost and Various Cost Types
Cost and Various Cost Types
 
Logic Families ( Digital Electronics )
Logic Families ( Digital Electronics )Logic Families ( Digital Electronics )
Logic Families ( Digital Electronics )
 
ANSI-SPARC Architecture - (3-Tier Architecture)
ANSI-SPARC Architecture - (3-Tier Architecture)ANSI-SPARC Architecture - (3-Tier Architecture)
ANSI-SPARC Architecture - (3-Tier Architecture)
 
Transaction Properties(ACID Properties)
Transaction Properties(ACID Properties)Transaction Properties(ACID Properties)
Transaction Properties(ACID Properties)
 
AVL tree ( Balanced Binary Search Tree)-Data Structure
AVL tree ( Balanced Binary Search Tree)-Data StructureAVL tree ( Balanced Binary Search Tree)-Data Structure
AVL tree ( Balanced Binary Search Tree)-Data Structure
 

Recently uploaded

The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 

Recently uploaded (20)

The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 

STACK ( LIFO STRUCTURE) - Data Structure

  • 2. Introduction about stack A stack is a linear OR non-primitive list in which insertion and deletion operations are performed at only one end of the list. A stack is Last in First out (LIFO) Structure. A stack is a linear data structure in which elements are added and removed from one end, called top of stack. For example of stack is, consider a stack of plates on the counter in cafeteria. 450 TOP 100 300 230 124 BOTTOM Figure: Stack (vertical representation of stack)
  • 3. Operations on stack The insertion operation is referred to as a PUSH operation and deletion operation is referred to as a POP operation. The most accessible element in the stack is known as a TOP element and the least accessible element in the stack is known as a BOTTOM element. Since, the insertion and deletion operation are performed at only one end of the stack. Stack operations are listed below:- (1)Push: The operations that add an element to the top of the stack is called PUSH operation. It is used to insert an element into the stack. (2)Pop: The operation that delete top element from the top of stack is called POP. it is used to delete an element from stack (3)Peep: it is used to retrieve ith element from the top of the stack.
  • 4. Algorithm for PUSH Operation In push operation, we can add elements to the top of the stack, so before push operation, user must check the stack, it should not be a full. If stack is already full and when we try to add the elements then error occurs. It is called “Stack Over Flow” error. PUSH(S, TOP, VAL) This algorithm insert an element X to the top of the stack. The Stack is represented by vector S which contains N elements. TOP is a pointer which points to the top element of the Stack. 1.[Check for stack overflow] If TOP >= N then Write (‘Stack Overflow’) Return 2.[Increment TOP] TOP = TOP + 1 3.[Insert Element] S [TOP] = VAL 4.[Finished] Return
  • 5. Algorithm for POP Operation In POP operation, we can delete or remove an elements from top of the stack, so before pop operation, user must check the stack, stack should not be a empty. If the stack is empty, and we try to pop an element, then error occur. It is called “Stack under Flow” error. POP(S, TOP) ➢This algorithm removes an element from the Top of the Stack. ➢The Stack is represented by vector S which contains N elements. ➢TOP is a pointer which points to the top element of the Stack. 1.[Check for the Underflow on the Stack] If TOP = 0 then Write (‘STACK UNDERFLOW’) Exit 2.[Decrement Pointer] TOP = TOP - 1 3.[Return former top element of the stack] Return(S [TOP + 1])
  • 6. Algorithm of displaying in Stack DISPLAY(top,i,a[i]) 1.If top=0 then Print ‘Stack is empty’ Exit Else 2.For i=top to 0 Print a[i] End for 3.Exit
  • 8. Application of Stack ● To reverse a word. You push a given word to stack - letter by letter - and then pop letters from the stack. ● An "undo" mechanism in text editors; this operation is accomplished by keeping all text changes in a stack. ○ Undo/Redo stacks in Excel or Word. ● Language processing : ○ compiler's syntax check for matching braces is implemented by using stack. ● A stack of plates/books in a cupboard. ● A garage that is only one car wide. To remove the first car in we have to take out all the other cars in after it. ● Expression Evolution ● Expression conversion ● Function Call