SlideShare a Scribd company logo
4
Most read
8
Most read
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

PPTX
Stack Data Structure
PPT
Stacks
PPTX
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptx
PPTX
Data structure Stack
PPSX
Data Structure (Stack)
PPTX
Stack and Queue
PPTX
Queue Implementation Using Array & Linked List
PPTX
Conversion of Infix to Prefix and Postfix with Stack
Stack Data Structure
Stacks
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptx
Data structure Stack
Data Structure (Stack)
Stack and Queue
Queue Implementation Using Array & Linked List
Conversion of Infix to Prefix and Postfix with Stack

What's hot (20)

PPTX
Chapter 15 Lists
PPTX
PPTX
single linked list
PPTX
Double Linked List (Algorithm)
PPTX
linked list in data structure
PPTX
Stack project
PPTX
Pointer in C++
PPTX
Stacks IN DATA STRUCTURES
PPTX
Linked list
PPTX
Infix to postfix conversion
DOCX
Data Structures Using C Practical File
PPTX
Arrays In C++
PPTX
Stacks in DATA STRUCTURE
PPTX
Stack - Data Structure
PPTX
Linear data structure concepts
PPTX
Ppt on Linked list,stack,queue
PPT
Stack a Data Structure
PPTX
Tree traversal techniques
PPTX
List in Python
PPTX
linked list
Chapter 15 Lists
single linked list
Double Linked List (Algorithm)
linked list in data structure
Stack project
Pointer in C++
Stacks IN DATA STRUCTURES
Linked list
Infix to postfix conversion
Data Structures Using C Practical File
Arrays In C++
Stacks in DATA STRUCTURE
Stack - Data Structure
Linear data structure concepts
Ppt on Linked list,stack,queue
Stack a Data Structure
Tree traversal techniques
List in Python
linked list
Ad

Similar to STACK ( LIFO STRUCTURE) - Data Structure (20)

PDF
The Stack (Data Structccccccccccccccccccc
PPTX
stack_ppt_DSA(sudipta samanta).pptx push,pop,peek operation
PPT
Lect 15-16 Zaheer Abbas
PPTX
Data structure by Digvijay
PDF
Stack push pop
PDF
PPTX
Stack and its operations
PDF
4-Stack --------------------------------in C++.pdf
PPTX
The presentation on stack data structure
PDF
PPTX
Stacks in Data Structure
PPTX
Data Structure ARRAY REPRESENTATION OF STACKS
PPTX
Stack PPT.pptx
DOCX
Stacks in data structure
PDF
Chapter 5 Stack and Queue.pdf
PPTX
5.-Stacks.pptx
PPTX
STACK.pptx
PPTX
Introduction to stack
PDF
Stack concepts by Divya
The Stack (Data Structccccccccccccccccccc
stack_ppt_DSA(sudipta samanta).pptx push,pop,peek operation
Lect 15-16 Zaheer Abbas
Data structure by Digvijay
Stack push pop
Stack and its operations
4-Stack --------------------------------in C++.pdf
The presentation on stack data structure
Stacks in Data Structure
Data Structure ARRAY REPRESENTATION OF STACKS
Stack PPT.pptx
Stacks in data structure
Chapter 5 Stack and Queue.pdf
5.-Stacks.pptx
STACK.pptx
Introduction to stack
Stack concepts by Divya
Ad

More from Yaksh Jethva (7)

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

Recently uploaded (20)

PPTX
Cell Structure & Organelles in detailed.
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
Pre independence Education in Inndia.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
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 Đ...
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
master seminar digital applications in india
PPTX
Cell Types and Its function , kingdom of life
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
Complications of Minimal Access Surgery at WLH
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
Cell Structure & Organelles in detailed.
VCE English Exam - Section C Student Revision Booklet
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
O7-L3 Supply Chain Operations - ICLT Program
102 student loan defaulters named and shamed – Is someone you know on the list?
Renaissance Architecture: A Journey from Faith to Humanism
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
RMMM.pdf make it easy to upload and study
Pre independence Education in Inndia.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
Microbial disease of the cardiovascular and lymphatic systems
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
2.FourierTransform-ShortQuestionswithAnswers.pdf
master seminar digital applications in india
Cell Types and Its function , kingdom of life
Week 4 Term 3 Study Techniques revisited.pptx
Complications of Minimal Access Surgery at WLH
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Microbial diseases, their pathogenesis and prophylaxis

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