SlideShare a Scribd company logo
DATA STRUCTURE
A data structure is a particular way of organizing data in
a computer so that it can be used effectively.
STACK
Stack is a linear data structure which follows a particular order
in which the operations are performed.
It follows the LIFO principle which stands for Last In First Out.
Here, the element which is placed (inserted or added) last, is
accessed first.
It has only one pointer TOP that points the last or top most
element of Stack.
Insertion and Deletion in stack can only be done from top only.
EXAMPLES OF STACK
OPERATIONS OF STACK
Push() − Pushing (storing) an element on the stack.
Pop() − Removing (accessing) an element from the stack.
We also need to check the status of the stack
to use it efficiently :
Overflow( ) – To check if stack is full.
Underflow( ) – To check if stack is empty.
ALGORITHM OF PUSH OPERATION
 Step 1 − Start
 Step 2 – Checks if the stack is full.
 Step 3 − If the stack is full, displays “Overflow”.
 Step 4 − If the stack is not full, increments TOP to point to
next empty space.
 Step 5 − Adds data element to the stack location, where top is
pointing.
 Step 6 − End
IMPLEMENTATION OF PUSH
10 10
30
10
30
20
10
30
20
15
10
30
20
15
40
0
1
2
3
4 4
3
2
1
0
4
3
2
1
0
4
3
2
1
0 0
1
2
33
4 4
2
1
0
top = -
1
top =
0
top =
1
top =
2
top =
3
top =
4
CODE FOR PUSH OPERATION
void push(int data)
{
if (top == arr.length - 1)
System.out.println("Stack is Full");
else
{
arr[++top] = data;
System.out.println("Pushed data :" + arr[top]);
}
}
ALGORITHM OF POP OPERATION
 Step 1 − Start
 Step 2 − Checks if the stack is empty.
 Step 3 − If the stack is empty, displays “Underflow”.
 Step 4 − If the stack is not empty, access the data element at
which TOP is pointing.
 Step 5 − Decrease the value of top by 1.
 Step 6 − End.
IMPLEMENTATION OF POP
10
30
20
15
40
3
4
2
1
0
top =
4
10
30
20
15
0
1
2
3
4
top =
3
10
30
20
4
3
2
1
0
top =
2
10
30
4
3
2
1
0
top =
1
10
4
3
2
1
0
top =
0
0
1
2
3
4
top = -
1
CODE FOR POP OPERATION
int pop()
{
if (top < 0)
{
System.out.println("Stack Underflow");
return 0;
}
else
{
System.out.println("Popped data : " + arr[top]);
return arr[top--];
}
}
APPLICATIONS OF STACK
Conversion of expressions.
Function calling and return procedure.
Recursion handling.
Decimal to Binary conversion.
TYPES OF ARITHMETIC EXPRESSIONS
Infix Expression : Operator is placed between the operands.
Example : A+B
Prefix Expression : Operator is placed before the operands.
Example : +AB
Postfix Expression : Operator is placed after the operands.
Example : AB+
CONVERSION FROM INFIX TO POSTFIX
1. A + (B * C) – (D / E)
= A + B C * - D E /
= A B C * + - D E /
= A B C * + D E / -
2. (A / B + C) * (D / (E - F))
= (A B / + C ) * (D / E F –)
= (A B / C +) * D E F – /
= A B / C + D E F – / *
3. (M – N )/ (P* ( S – T) + K)
= (M N – ) / (P* (S T – ) + K)
= ( M N –) / ((P S T – *) + K)
= ( M N –) / (P S T – * K +)
= M N – P S T – * K + /
CONVERSION FROM INFIX TO PREFIX
1. A + (B * C) – (D / E)
= A + * B C - / D E
= + A * B C - / D E
= - + A * B C / D E
2. (A / B + C) * (D / (E - F))
= (/ A B + C) * (D / - E F)
= (+ / A B C) * ( / D – E F)
= * + / A B C / D – E F
3. (M – N )/ (P* ( S – T) + K)
= ( - M N ) / (P * ( - S T ) + K)
= (- M N ) / ( (* P – S T) + K)
= (- M N ) / (+ * P – S T K)
= / - M N + * P – S T K

More Related Content

What's hot

Stack_Application_Infix_Prefix.pptx
Stack_Application_Infix_Prefix.pptxStack_Application_Infix_Prefix.pptx
Stack_Application_Infix_Prefix.pptx
sandeep54552
 
Stacks in Data Structure
Stacks in Data StructureStacks in Data Structure
Stacks in Data Structure
Lovely Professional University
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stackvaibhav2910
 
Stacks
StacksStacks
Stack project
Stack projectStack project
Stack project
Amr Aboelgood
 
Stacks in DATA STRUCTURE
Stacks in DATA STRUCTUREStacks in DATA STRUCTURE
Stacks in DATA STRUCTURE
Mandeep Singh
 
STACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureSTACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data Structure
Yaksh Jethva
 
Stack
StackStack
Stack - Data Structure
Stack - Data StructureStack - Data Structure
Stack - Data Structure
Bhavesh Sanghvi
 
Data structure Stack
Data structure StackData structure Stack
Data structure Stack
Praveen Vishwakarma
 
Stack Data Structure & It's Application
Stack Data Structure & It's Application Stack Data Structure & It's Application
Stack Data Structure & It's Application Tech_MX
 
Stack & queue
Stack & queueStack & queue
Stack & queue
Siddique Ibrahim
 
Stack of Data structure
Stack of Data structureStack of Data structure
Stack of Data structure
Sheikh Monirul Hasan
 
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.
 
Application of Stack - Yadraj Meena
Application of Stack - Yadraj MeenaApplication of Stack - Yadraj Meena
Application of Stack - Yadraj Meena
Dipayan Sarkar
 
Stacks and Queue - Data Structures
Stacks and Queue - Data StructuresStacks and Queue - Data Structures
Stacks and Queue - Data Structures
Dr. Jasmine Beulah Gnanadurai
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
Afaq Mansoor Khan
 
Stack in Sata Structure
Stack in Sata StructureStack in Sata Structure
Stack in Sata Structure
Muhazzab Chouhadry
 

What's hot (20)

Stack_Application_Infix_Prefix.pptx
Stack_Application_Infix_Prefix.pptxStack_Application_Infix_Prefix.pptx
Stack_Application_Infix_Prefix.pptx
 
Stacks in Data Structure
Stacks in Data StructureStacks in Data Structure
Stacks in Data Structure
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
 
Stacks
StacksStacks
Stacks
 
Stack project
Stack projectStack project
Stack project
 
Stacks in DATA STRUCTURE
Stacks in DATA STRUCTUREStacks in DATA STRUCTURE
Stacks in DATA STRUCTURE
 
STACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureSTACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data Structure
 
Stack
StackStack
Stack
 
Stack - Data Structure
Stack - Data StructureStack - Data Structure
Stack - Data Structure
 
Stack a Data Structure
Stack a Data StructureStack a Data Structure
Stack a Data Structure
 
Data structure Stack
Data structure StackData structure Stack
Data structure Stack
 
Stack Data Structure & It's Application
Stack Data Structure & It's Application Stack Data Structure & It's Application
Stack Data Structure & It's Application
 
Stack & queue
Stack & queueStack & queue
Stack & queue
 
Stack of Data structure
Stack of Data structureStack of Data structure
Stack of Data structure
 
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.
 
Stack
StackStack
Stack
 
Application of Stack - Yadraj Meena
Application of Stack - Yadraj MeenaApplication of Stack - Yadraj Meena
Application of Stack - Yadraj Meena
 
Stacks and Queue - Data Structures
Stacks and Queue - Data StructuresStacks and Queue - Data Structures
Stacks and Queue - Data Structures
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
Stack in Sata Structure
Stack in Sata StructureStack in Sata Structure
Stack in Sata Structure
 

Similar to Stack Data Structure

Stack
StackStack
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
Balwant Gorad
 
Stacks-and-Queues.pdf
Stacks-and-Queues.pdfStacks-and-Queues.pdf
Stacks-and-Queues.pdf
TobyWtf
 
Stack and its operations
Stack and its operationsStack and its operations
Stack and its operations
V.V.Vanniaperumal College for Women
 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacks
maamir farooq
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
DurgaDeviCbit
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
AliRaza899305
 
03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays03 stacks and_queues_using_arrays
03 stacks and_queues_using_arraystameemyousaf
 
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
 
04 stacks
04 stacks04 stacks
04 stacks
Rajan Gautam
 
Stack
StackStack
Stack Operation In Data Structure
Stack Operation In Data Structure Stack Operation In Data Structure
Stack Operation In Data Structure
DivyeshKumar Jagatiya
 
Stack data structure
Stack data structureStack data structure
Stack data structure
rogineojerio020496
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
pinakspatel
 
DS UNIT 1.pdf
DS UNIT 1.pdfDS UNIT 1.pdf
DS UNIT 1.pdf
SeethaDinesh
 
DS UNIT 1.pdf
DS UNIT 1.pdfDS UNIT 1.pdf
DS UNIT 1.pdf
SeethaDinesh
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
Vineeta Garg
 
Chapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdfChapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdf
GirT2
 
Data structure week y 5
Data structure week y 5Data structure week y 5
Data structure week y 5
karmuhtam
 

Similar to Stack Data Structure (20)

Stack
StackStack
Stack
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
 
Stacks-and-Queues.pdf
Stacks-and-Queues.pdfStacks-and-Queues.pdf
Stacks-and-Queues.pdf
 
Stack and its operations
Stack and its operationsStack and its operations
Stack and its operations
 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacks
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
 
03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays
 
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
 
04 stacks
04 stacks04 stacks
04 stacks
 
Stack
StackStack
Stack
 
Stack Operation In Data Structure
Stack Operation In Data Structure Stack Operation In Data Structure
Stack Operation In Data Structure
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
 
DS UNIT 1.pdf
DS UNIT 1.pdfDS UNIT 1.pdf
DS UNIT 1.pdf
 
DS UNIT 1.pdf
DS UNIT 1.pdfDS UNIT 1.pdf
DS UNIT 1.pdf
 
Team 3
Team 3Team 3
Team 3
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
 
Chapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdfChapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdf
 
Data structure week y 5
Data structure week y 5Data structure week y 5
Data structure week y 5
 

Recently uploaded

June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
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
 
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
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
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
 
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
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
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
 
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
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 

Recently uploaded (20)

June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
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
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
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
 
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...
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
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
 
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
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 

Stack Data Structure

  • 1. DATA STRUCTURE A data structure is a particular way of organizing data in a computer so that it can be used effectively.
  • 2. STACK Stack is a linear data structure which follows a particular order in which the operations are performed. It follows the LIFO principle which stands for Last In First Out. Here, the element which is placed (inserted or added) last, is accessed first. It has only one pointer TOP that points the last or top most element of Stack. Insertion and Deletion in stack can only be done from top only.
  • 4. OPERATIONS OF STACK Push() − Pushing (storing) an element on the stack. Pop() − Removing (accessing) an element from the stack. We also need to check the status of the stack to use it efficiently : Overflow( ) – To check if stack is full. Underflow( ) – To check if stack is empty.
  • 5. ALGORITHM OF PUSH OPERATION  Step 1 − Start  Step 2 – Checks if the stack is full.  Step 3 − If the stack is full, displays “Overflow”.  Step 4 − If the stack is not full, increments TOP to point to next empty space.  Step 5 − Adds data element to the stack location, where top is pointing.  Step 6 − End
  • 6. IMPLEMENTATION OF PUSH 10 10 30 10 30 20 10 30 20 15 10 30 20 15 40 0 1 2 3 4 4 3 2 1 0 4 3 2 1 0 4 3 2 1 0 0 1 2 33 4 4 2 1 0 top = - 1 top = 0 top = 1 top = 2 top = 3 top = 4
  • 7. CODE FOR PUSH OPERATION void push(int data) { if (top == arr.length - 1) System.out.println("Stack is Full"); else { arr[++top] = data; System.out.println("Pushed data :" + arr[top]); } }
  • 8. ALGORITHM OF POP OPERATION  Step 1 − Start  Step 2 − Checks if the stack is empty.  Step 3 − If the stack is empty, displays “Underflow”.  Step 4 − If the stack is not empty, access the data element at which TOP is pointing.  Step 5 − Decrease the value of top by 1.  Step 6 − End.
  • 9. IMPLEMENTATION OF POP 10 30 20 15 40 3 4 2 1 0 top = 4 10 30 20 15 0 1 2 3 4 top = 3 10 30 20 4 3 2 1 0 top = 2 10 30 4 3 2 1 0 top = 1 10 4 3 2 1 0 top = 0 0 1 2 3 4 top = - 1
  • 10. CODE FOR POP OPERATION int pop() { if (top < 0) { System.out.println("Stack Underflow"); return 0; } else { System.out.println("Popped data : " + arr[top]); return arr[top--]; } }
  • 11. APPLICATIONS OF STACK Conversion of expressions. Function calling and return procedure. Recursion handling. Decimal to Binary conversion.
  • 12. TYPES OF ARITHMETIC EXPRESSIONS Infix Expression : Operator is placed between the operands. Example : A+B Prefix Expression : Operator is placed before the operands. Example : +AB Postfix Expression : Operator is placed after the operands. Example : AB+
  • 13. CONVERSION FROM INFIX TO POSTFIX 1. A + (B * C) – (D / E) = A + B C * - D E / = A B C * + - D E / = A B C * + D E / -
  • 14. 2. (A / B + C) * (D / (E - F)) = (A B / + C ) * (D / E F –) = (A B / C +) * D E F – / = A B / C + D E F – / * 3. (M – N )/ (P* ( S – T) + K) = (M N – ) / (P* (S T – ) + K) = ( M N –) / ((P S T – *) + K) = ( M N –) / (P S T – * K +) = M N – P S T – * K + /
  • 15. CONVERSION FROM INFIX TO PREFIX 1. A + (B * C) – (D / E) = A + * B C - / D E = + A * B C - / D E = - + A * B C / D E
  • 16. 2. (A / B + C) * (D / (E - F)) = (/ A B + C) * (D / - E F) = (+ / A B C) * ( / D – E F) = * + / A B C / D – E F 3. (M – N )/ (P* ( S – T) + K) = ( - M N ) / (P * ( - S T ) + K) = (- M N ) / ( (* P – S T) + K) = (- M N ) / (+ * P – S T K) = / - M N + * P – S T K