SlideShare a Scribd company logo
1 of 16
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 (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

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 QueueBalwant Gorad
 
Stacks-and-Queues.pdf
Stacks-and-Queues.pdfStacks-and-Queues.pdf
Stacks-and-Queues.pdfTobyWtf
 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacksmaamir farooq
 
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.pptxShivam Kumar
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-listpinakspatel
 
Chapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdfChapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdfGirT2
 
Data structure week y 5
Data structure week y 5Data structure week y 5
Data structure week y 5karmuhtam
 

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

KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 

Recently uploaded (20)

KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 

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