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

PPTX
Queue Data Structure
PPTX
Data structure by Digvijay
PPT
Stacks overview with its applications
PPT
PPTX
Project of data structure
PPTX
Introduction To Stack
PPTX
STACKS IN DATASTRUCTURE
PPTX
Stack_Data_Structure.pptx
Queue Data Structure
Data structure by Digvijay
Stacks overview with its applications
Project of data structure
Introduction To Stack
STACKS IN DATASTRUCTURE
Stack_Data_Structure.pptx

What's hot (20)

PPTX
Stack_Application_Infix_Prefix.pptx
PPTX
Stacks in Data Structure
PPTX
Introduction to stack
PPT
PPTX
Stack project
PPTX
Stacks in DATA STRUCTURE
PDF
STACK ( LIFO STRUCTURE) - Data Structure
PPSX
PPTX
Stack - Data Structure
PPT
Stack a Data Structure
PPTX
Data structure Stack
PPT
Stack Data Structure & It's Application
PPT
Stack & queue
PPTX
Stack of Data structure
PPT
stack and queue array implementation in java.
PPT
PPTX
Application of Stack - Yadraj Meena
PPTX
Stacks and Queue - Data Structures
PPTX
Stack Data Structure
PPTX
Stack in Sata Structure
Stack_Application_Infix_Prefix.pptx
Stacks in Data Structure
Introduction to stack
Stack project
Stacks in DATA STRUCTURE
STACK ( LIFO STRUCTURE) - Data Structure
Stack - Data Structure
Stack a Data Structure
Data structure Stack
Stack Data Structure & It's Application
Stack & queue
Stack of Data structure
stack and queue array implementation in java.
Application of Stack - Yadraj Meena
Stacks and Queue - Data Structures
Stack Data Structure
Stack in Sata Structure
Ad

Similar to Stack Data Structure (20)

PDF
PDF
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
PPTX
stack_ppt_DSA(sudipta samanta).pptx push,pop,peek operation
PDF
Stacks-and-Queues.pdf
PPTX
Introduction to information about Data Structure.pptx
PPTX
Stack and its operations
PDF
Data structures stacks
PDF
stacks and queues
PPTX
Stack.pptx
PPT
03 stacks and_queues_using_arrays
PPTX
Stack,queue and linked list data structure.pptx
PPTX
Stack and its operation implemented with array new - Copy.pptx
PPTX
The presentation on stack data structure
PPTX
STACKS implimentarions AND stack applications .pptx
PDF
04 stacks
PPTX
Data Structures Stack and Queue Data Structures
PDF
PPT
Stack Operation In Data Structure
PPTX
Stack data structure
PDF
Stacks,queues,linked-list
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
stack_ppt_DSA(sudipta samanta).pptx push,pop,peek operation
Stacks-and-Queues.pdf
Introduction to information about Data Structure.pptx
Stack and its operations
Data structures stacks
stacks and queues
Stack.pptx
03 stacks and_queues_using_arrays
Stack,queue and linked list data structure.pptx
Stack and its operation implemented with array new - Copy.pptx
The presentation on stack data structure
STACKS implimentarions AND stack applications .pptx
04 stacks
Data Structures Stack and Queue Data Structures
Stack Operation In Data Structure
Stack data structure
Stacks,queues,linked-list
Ad

Recently uploaded (20)

PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Cell Types and Its function , kingdom of life
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Computing-Curriculum for Schools in Ghana
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PDF
RMMM.pdf make it easy to upload and study
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Sports Quiz easy sports quiz sports quiz
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
Cell Types and Its function , kingdom of life
Microbial diseases, their pathogenesis and prophylaxis
TR - Agricultural Crops Production NC III.pdf
Computing-Curriculum for Schools in Ghana
O5-L3 Freight Transport Ops (International) V1.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
STATICS OF THE RIGID BODIES Hibbelers.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
GDM (1) (1).pptx small presentation for students
RMMM.pdf make it easy to upload and study
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Sports Quiz easy sports quiz sports quiz
Microbial disease of the cardiovascular and lymphatic systems
Renaissance Architecture: A Journey from Faith to Humanism
2.FourierTransform-ShortQuestionswithAnswers.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.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