SlideShare a Scribd company logo
1 of 19
2.5 Stack ADT
Definition
Basic Operations in Stack ADT
Advantages of Stack ADT
Disadvantages of Stack ADT
Application of Stack ADT
Prepared by
Mrs. G. Mareeswari,
Assistant professor,
Department of Information technology
Ramco Institute of Technology
Rajapalayam
Definition:
• A stack is a linear data structure in which the insertion of a new
element and removal of an existing element takes place at only one
end represented as the top of the stack.
• Stack is called a Last In First Out (LIFO) structure because the last
element which is added to the stack is the first element which is
deleted from the stack
• Only access the stack is the top element
Basic Operations on Stack
In order to make manipulations in a stack, there are certain
operations provided to us.
• push() to insert an element into the stack
• pop() to remove an element from the stack
• top()/peek() Returns the top element of
the stack without removing it.
• isEmpty() returns true if stack is empty else false.
• size() returns the size of stack.
• display() print all the elements in the stack
Implementation of Stack ADT
• There are several ways to implement the stack ADT
Some are
Implementation of Stack ADT using list
Linked list implementation of Stack ADT
Implementation of Stack ADT using list:
The stack is formed by using the list. All the operations
regarding the stack are performed using list functions in python.
Implementation of Stack ADT using list
• Push Operation – Insert an element at the end of the list so use
append function of list
• Pop Operation – Delete an element from the end of the list so use
pop function of list
• Peek Operation – return the last element in the list without removing
so access the last element by its index.
• IsEmpty operation – check the list is empty or not
• Size operation – return the length of the list
Operations in implementation of stack using list
i) Creation of stack:
class Stack:
def __init__(self, size):
self.size = size
self.stack = []
ii) Push operation:
def push(self, item):
if len(self.stack) < self.size:
self.stack.append(item)
print("Pushed item:", item)
else:
print("Stack Overflow")
Operations in implementation of stack using list
iii) Pop operation:
def pop(self):
if len(self.stack) > 0:
item = self.stack.pop()
print("Popped item:", item)
else:
print("Stack Underflow")
iv) Peek operation:
def peek(self):
if len(self.stack) > 0:
print("Top item:", self.stack[-1])
else:
print("Stack is empty")
Operations in implementation of stack using list
v) Display operation
def display(self):
if len(self.stack) > 0:
print("Stack:", self.stack)
else:
print("Stack is empty")
vi) Size Operation
def size(self):
return len(self.stack)
Example:
stack = Stack(5)
stack.push(1)
stack.push(2)
stack.push(3)
stack.display()
stack.peek()
stack.pop()
stack.display()
stack.pop()
stack.pop()
stack.pop()
stack.display()
output:
Pushed item: 1
Pushed item: 2
Pushed item: 3
Stack: [1, 2, 3]
Top item: 3
Popped item: 3
Stack: [1, 2]
Popped item: 2
Popped item: 1
Stack Underflow
Stack is empty
Linked list Implementation of Stack ADT
• We can use linked list to implement stack. Linked list
allocates the memory dynamically.
• However, time complexity in both the scenario is same for all
the operations i.e. push, pop and peek.
• In linked list implementation of stack, the nodes are
maintained non-contiguously in the memory.
• Each node contains a pointer to its immediate successor
node in the stack.
Linked list Implementation of Stack ADT
The top most node in the stack always contains null in its address field.
Operations in linked list implementation of stack
i) Creation of stack:
class Node:
def __init__(self, data):
self.data = data
self.next = None
class Stack:
def __init__(self):
self.top = None
ii) Push operation:
def push(self, item):
new_node = Node(item)
new_node.next = self.top
self.top = new_node
print("Pushed item:", item)
Operations in linked list implementation of stack
iii) Pop operation:
def pop(self):
if self.top is not None:
item = self.top.data
self.top = self.top.next
print("Popped item:", item)
else:
print("Stack Underflow")
iv) Peek operation:
def peek(self):
if self.top is not None:
print("Top item:", self.top.data)
else:
print("Stack is empty")
Operations in linked list implementation of stack
v) display()
def display(self):
if self.top is not None:
current = self.top
stack_items = []
while current:
stack_items.append(current.data)
current = current.next
print("Stack:", stack_items)
else:
print("Stack is empty")
Example
stack = Stack()
stack.push(1)
stack.push(2)
stack.push(3)
stack.display()
stack.peek()
stack.pop()
stack.display()
stack.pop()
stack.pop()
stack.pop()
stack.display()
output:
Pushed item: 1
Pushed item: 2
Pushed item: 3
Stack: [1, 2, 3]
Top item: 3
Popped item: 3
Stack: [1, 2]
Popped item: 2
Popped item: 1
Stack Underflow
Stack is empty
Advantage of stack
• Easy implementation: Stack data structure is easy to implement using arrays or
linked lists, and its operations are simple to understand and implement.
• Efficient memory utilization: Stack uses a contiguous block of memory, making
it more efficient in memory utilization as compared to other data structures.
• Fast access time: Stack data structure provides fast access time for adding and
removing elements as the elements are added and removed from the top of the
stack.
• Helps in function calls: Stack data structure is used to store function calls and
their states, which helps in the efficient implementation of recursive function calls.
• Supports backtracking: Stack data structure supports backtracking algorithms,
which are used in problem-solving to explore all possible solutions by storing the
previous states.
• Used in Compiler Design: Stack data structure is used in compiler design for
parsing and syntax analysis of programming languages.
Disdvantage of stack
• Limited capacity: Stack data structure has a limited capacity as it can
only hold a fixed number of elements. If the stack becomes full,
adding new elements may result in stack overflow, leading to the loss
of data.
• No random access: Stack data structure does not allow for random
access to its elements, and it only allows for adding and removing
elements from the top of the stack. To access an element in the
middle of the stack, all the elements above it must be removed.
Application of stack
• CD/DVD stand.
• Stack of books in a book shop.
• Call center systems.
• Undo and Redo mechanism in text editors.
• The history of a web browser is stored in the form of a stack.
• Call logs, E-mails, and Google photos in any gallery are also stored in form
of a stack.
• YouTube downloads and Notifications are also shown in LIFO format(the
latest appears first ).
• Allocation of memory by an operating system while executing a process.

More Related Content

What's hot (20)

Stacks, Queues, Deques
Stacks, Queues, DequesStacks, Queues, Deques
Stacks, Queues, Deques
 
Queues
QueuesQueues
Queues
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
 
Stack_Data_Structure.pptx
Stack_Data_Structure.pptxStack_Data_Structure.pptx
Stack_Data_Structure.pptx
 
Data structures
Data structuresData structures
Data structures
 
Queue in Data Structure
Queue in Data StructureQueue in Data Structure
Queue in Data Structure
 
Shell sort in Data Structure Using C
Shell sort in Data Structure Using CShell sort in Data Structure Using C
Shell sort in Data Structure Using C
 
List in java
List in javaList in java
List in java
 
Singly & Circular Linked list
Singly & Circular Linked listSingly & Circular Linked list
Singly & Circular Linked list
 
Data structure stack&queue basics
Data structure stack&queue   basicsData structure stack&queue   basics
Data structure stack&queue basics
 
Binary search tree operations
Binary search tree operationsBinary search tree operations
Binary search tree operations
 
Queues in C++
Queues in C++Queues in C++
Queues in C++
 
Graphs bfs dfs
Graphs bfs dfsGraphs bfs dfs
Graphs bfs dfs
 
Linked list
Linked list Linked list
Linked list
 
Unit I - Evaluation of expression
Unit I - Evaluation of expressionUnit I - Evaluation of expression
Unit I - Evaluation of expression
 
Priority queue in DSA
Priority queue in DSAPriority queue in DSA
Priority queue in DSA
 
Queues
Queues Queues
Queues
 
Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 

Similar to Stack ADT: LIFO Data Structure for Function Calls

Similar to Stack ADT: LIFO Data Structure for Function Calls (20)

9 python data structure-2
9 python data structure-29 python data structure-2
9 python data structure-2
 
Data structure , stack , queue
Data structure , stack , queueData structure , stack , queue
Data structure , stack , queue
 
stack_presentaton_HUSNAIN[2].pojklklklptx
stack_presentaton_HUSNAIN[2].pojklklklptxstack_presentaton_HUSNAIN[2].pojklklklptx
stack_presentaton_HUSNAIN[2].pojklklklptx
 
Stacks
StacksStacks
Stacks
 
Stacks in Data Structure
Stacks in Data StructureStacks in Data Structure
Stacks in Data Structure
 
stack slide vghbjnkmfgvhbjnmkgvbhjnkmgbhjnkm
stack slide vghbjnkmfgvhbjnmkgvbhjnkmgbhjnkmstack slide vghbjnkmfgvhbjnmkgvbhjnkmgbhjnkm
stack slide vghbjnkmfgvhbjnmkgvbhjnkmgbhjnkm
 
2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS
 
stack coding.pptx
stack coding.pptxstack coding.pptx
stack coding.pptx
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queue
 
LectureNotes-06-DSA
LectureNotes-06-DSALectureNotes-06-DSA
LectureNotes-06-DSA
 
notes.pdf
notes.pdfnotes.pdf
notes.pdf
 
Ch03_stacks_and_queues.ppt
Ch03_stacks_and_queues.pptCh03_stacks_and_queues.ppt
Ch03_stacks_and_queues.ppt
 
Stack in Sata Structure
Stack in Sata StructureStack in Sata Structure
Stack in Sata Structure
 
Stack - Operations and Applications
Stack - Operations and ApplicationsStack - Operations and Applications
Stack - Operations and Applications
 
Unit i(dsc++)
Unit i(dsc++)Unit i(dsc++)
Unit i(dsc++)
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Stack and its applications
Stack and its applicationsStack and its applications
Stack and its applications
 
Unit I-Data structures stack & Queue
Unit I-Data structures stack & QueueUnit I-Data structures stack & Queue
Unit I-Data structures stack & Queue
 
Stacks
StacksStacks
Stacks
 
Ds
DsDs
Ds
 

Recently uploaded

pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture designssuser87fa0c1
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIkoyaldeepu123
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage examplePragyanshuParadkar1
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 

Recently uploaded (20)

pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture design
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AI
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage example
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 

Stack ADT: LIFO Data Structure for Function Calls

  • 1. 2.5 Stack ADT Definition Basic Operations in Stack ADT Advantages of Stack ADT Disadvantages of Stack ADT Application of Stack ADT Prepared by Mrs. G. Mareeswari, Assistant professor, Department of Information technology Ramco Institute of Technology Rajapalayam
  • 2. Definition: • A stack is a linear data structure in which the insertion of a new element and removal of an existing element takes place at only one end represented as the top of the stack. • Stack is called a Last In First Out (LIFO) structure because the last element which is added to the stack is the first element which is deleted from the stack • Only access the stack is the top element
  • 3. Basic Operations on Stack In order to make manipulations in a stack, there are certain operations provided to us. • push() to insert an element into the stack • pop() to remove an element from the stack • top()/peek() Returns the top element of the stack without removing it. • isEmpty() returns true if stack is empty else false. • size() returns the size of stack. • display() print all the elements in the stack
  • 4. Implementation of Stack ADT • There are several ways to implement the stack ADT Some are Implementation of Stack ADT using list Linked list implementation of Stack ADT Implementation of Stack ADT using list: The stack is formed by using the list. All the operations regarding the stack are performed using list functions in python.
  • 5. Implementation of Stack ADT using list • Push Operation – Insert an element at the end of the list so use append function of list • Pop Operation – Delete an element from the end of the list so use pop function of list • Peek Operation – return the last element in the list without removing so access the last element by its index. • IsEmpty operation – check the list is empty or not • Size operation – return the length of the list
  • 6.
  • 7. Operations in implementation of stack using list i) Creation of stack: class Stack: def __init__(self, size): self.size = size self.stack = [] ii) Push operation: def push(self, item): if len(self.stack) < self.size: self.stack.append(item) print("Pushed item:", item) else: print("Stack Overflow")
  • 8. Operations in implementation of stack using list iii) Pop operation: def pop(self): if len(self.stack) > 0: item = self.stack.pop() print("Popped item:", item) else: print("Stack Underflow") iv) Peek operation: def peek(self): if len(self.stack) > 0: print("Top item:", self.stack[-1]) else: print("Stack is empty")
  • 9. Operations in implementation of stack using list v) Display operation def display(self): if len(self.stack) > 0: print("Stack:", self.stack) else: print("Stack is empty") vi) Size Operation def size(self): return len(self.stack)
  • 10. Example: stack = Stack(5) stack.push(1) stack.push(2) stack.push(3) stack.display() stack.peek() stack.pop() stack.display() stack.pop() stack.pop() stack.pop() stack.display() output: Pushed item: 1 Pushed item: 2 Pushed item: 3 Stack: [1, 2, 3] Top item: 3 Popped item: 3 Stack: [1, 2] Popped item: 2 Popped item: 1 Stack Underflow Stack is empty
  • 11. Linked list Implementation of Stack ADT • We can use linked list to implement stack. Linked list allocates the memory dynamically. • However, time complexity in both the scenario is same for all the operations i.e. push, pop and peek. • In linked list implementation of stack, the nodes are maintained non-contiguously in the memory. • Each node contains a pointer to its immediate successor node in the stack.
  • 12. Linked list Implementation of Stack ADT The top most node in the stack always contains null in its address field.
  • 13. Operations in linked list implementation of stack i) Creation of stack: class Node: def __init__(self, data): self.data = data self.next = None class Stack: def __init__(self): self.top = None ii) Push operation: def push(self, item): new_node = Node(item) new_node.next = self.top self.top = new_node print("Pushed item:", item)
  • 14. Operations in linked list implementation of stack iii) Pop operation: def pop(self): if self.top is not None: item = self.top.data self.top = self.top.next print("Popped item:", item) else: print("Stack Underflow") iv) Peek operation: def peek(self): if self.top is not None: print("Top item:", self.top.data) else: print("Stack is empty")
  • 15. Operations in linked list implementation of stack v) display() def display(self): if self.top is not None: current = self.top stack_items = [] while current: stack_items.append(current.data) current = current.next print("Stack:", stack_items) else: print("Stack is empty")
  • 16. Example stack = Stack() stack.push(1) stack.push(2) stack.push(3) stack.display() stack.peek() stack.pop() stack.display() stack.pop() stack.pop() stack.pop() stack.display() output: Pushed item: 1 Pushed item: 2 Pushed item: 3 Stack: [1, 2, 3] Top item: 3 Popped item: 3 Stack: [1, 2] Popped item: 2 Popped item: 1 Stack Underflow Stack is empty
  • 17. Advantage of stack • Easy implementation: Stack data structure is easy to implement using arrays or linked lists, and its operations are simple to understand and implement. • Efficient memory utilization: Stack uses a contiguous block of memory, making it more efficient in memory utilization as compared to other data structures. • Fast access time: Stack data structure provides fast access time for adding and removing elements as the elements are added and removed from the top of the stack. • Helps in function calls: Stack data structure is used to store function calls and their states, which helps in the efficient implementation of recursive function calls. • Supports backtracking: Stack data structure supports backtracking algorithms, which are used in problem-solving to explore all possible solutions by storing the previous states. • Used in Compiler Design: Stack data structure is used in compiler design for parsing and syntax analysis of programming languages.
  • 18. Disdvantage of stack • Limited capacity: Stack data structure has a limited capacity as it can only hold a fixed number of elements. If the stack becomes full, adding new elements may result in stack overflow, leading to the loss of data. • No random access: Stack data structure does not allow for random access to its elements, and it only allows for adding and removing elements from the top of the stack. To access an element in the middle of the stack, all the elements above it must be removed.
  • 19. Application of stack • CD/DVD stand. • Stack of books in a book shop. • Call center systems. • Undo and Redo mechanism in text editors. • The history of a web browser is stored in the form of a stack. • Call logs, E-mails, and Google photos in any gallery are also stored in form of a stack. • YouTube downloads and Notifications are also shown in LIFO format(the latest appears first ). • Allocation of memory by an operating system while executing a process.