SlideShare a Scribd company logo
1 of 15
Unit III
Stacks and Queues
Unit III
Stacks and Queues
COs Mapped – CO2, CO5
• Concept of stack and queues as ADT,
• Implementation of stacks using sequential and linked
organization,
• linear queue,
• circular queue using sequential and linked
organization,
• Priority Queue,
• Deque,
• Application of stack for expression conversion,
evaluation, recursion and backtracking
• Application of queue in job scheduling
What is a Stack?
• A Stack is a linear data structure that follows
the LIFO (Last-In-First-Out) principle.
• Stack has one end, whereas the Queue has
two ends (front and rear).
• It contains only one pointer top
pointer pointing to the topmost element of
the stack.
• Whenever an element is added in the stack, it
is added on the top of the stack, and the
element can be deleted only from the stack.
• In other words, a stack can be defined as a
container in which insertion and deletion can
be done from the one end known as the top
of the stack.
Some key points related to stack
• It is called as stack because it behaves like a
real-world stack, piles of books, etc.
• A Stack is an abstract data type with a pre-
defined capacity, which means that it can
store the elements of a limited size.
• It is a data structure that follows some order
to insert and delete the elements, and that
order can be LIFO or FILO.
Working of Stack
• Stack works on the LIFO pattern. As we can
observe in the below figure there are five
memory blocks in the stack; therefore, the
size of the stack is 5.
• Suppose we want to store the elements in a
stack and let's assume that stack is empty. We
have taken the stack of size 5 as shown below
in which we are pushing the elements one by
one until the stack becomes full.
• Since our stack is full as the size of the stack is
5.
• In the above cases, we can observe that it
goes from the top to the bottom when we
were entering the new element in the stack.
• The stack gets filled up from the bottom to
the top.
• When we perform the delete operation on the
stack, there is only one way for entry and exit
as the other end is closed.
• It follows the LIFO pattern, which means that
the value entered first will be removed last. In
the above case, the value 5 is entered first, so
it will be removed only after the deletion of all
the other elements.
Stack ADT in Data Structures
• Let us now see the data object, operations
and axioms associated with stack.
• Any sets of elements that are of the same
data type can be used as a data object for
stack
• E.g.stack of integers, stack of students etc.
Stack ADT in Data Structures
• The abstract datatype is special kind of datatype,
whose behavior is defined by a set of values and
set of operations.
• The keyword “Abstract” is used as we can use
these datatypes, we can perform different
operations.
• But how those operations are working that is
totally hidden from the user.
• The ADT is made of with primitive datatypes, but
operation logics are hidden.
Here we will see the stack ADT. These are few
operations or functions of the Stack ADT.
1. isFull(), This is used to check whether stack is full
or not
2. isEmpry(), This is used to check whether stack is
empty or not
3. push(x), This is used to push x into the stack
4. pop(), This is used to delete one element from
top of the stack
5. peek(), This is used to get the top most element
of the stack
6. size(), this function is used to get number of
elements present into the stack
Standard Stack Operations
The following are some common operations implemented on
the stack:
1. push(): When we insert an element in a stack then the
operation is known as a push. If the stack is full then the
overflow condition occurs.
2. pop(): When we delete an element from the stack, the
operation is known as a pop. If the stack is empty means
that no element exists in the stack, this state is known as an
underflow state.
3. isEmpty(): It determines whether the stack is empty or not.
4. isFull(): It determines whether the stack is full or not.'
5. peek(): It returns the element at the given position.
6. count(): It returns the total number of elements available in
a stack.
7. change(): It changes the element at the given position.
8. display(): It prints all the elements available in the stack.

More Related Content

Similar to Stacks and Queue,Concept of Stack,LIFO,Fifo,

Similar to Stacks and Queue,Concept of Stack,LIFO,Fifo, (20)

Chapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdfChapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdf
 
stacks and queues for public
stacks and queues for publicstacks and queues for public
stacks and queues for public
 
Data Structures
Data StructuresData Structures
Data Structures
 
Queues
Queues Queues
Queues
 
STACKS AND QUEUES.pptx
STACKS AND QUEUES.pptxSTACKS AND QUEUES.pptx
STACKS AND QUEUES.pptx
 
STACKS AND QUEUES.pptx
STACKS AND QUEUES.pptxSTACKS AND QUEUES.pptx
STACKS AND QUEUES.pptx
 
2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS
 
DSA_Lecture4-Stack.pptx
DSA_Lecture4-Stack.pptxDSA_Lecture4-Stack.pptx
DSA_Lecture4-Stack.pptx
 
Javascript stack
Javascript   stackJavascript   stack
Javascript stack
 
Ds stack & queue
Ds   stack & queueDs   stack & queue
Ds stack & queue
 
Chapter 4 stack
Chapter 4 stackChapter 4 stack
Chapter 4 stack
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
 
5.-Stacks.pptx
5.-Stacks.pptx5.-Stacks.pptx
5.-Stacks.pptx
 
Data structures
Data structuresData structures
Data structures
 
Lecture9_StackQueue.ppt
Lecture9_StackQueue.pptLecture9_StackQueue.ppt
Lecture9_StackQueue.ppt
 
StackQueue.ppt
StackQueue.pptStackQueue.ppt
StackQueue.ppt
 
Queue ADT for data structure for computer
Queue ADT for data structure for computerQueue ADT for data structure for computer
Queue ADT for data structure for computer
 
Stack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi LecturerStack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi Lecturer
 
stack 1.pdf
stack 1.pdfstack 1.pdf
stack 1.pdf
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 

Recently uploaded

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 

Recently uploaded (20)

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 

Stacks and Queue,Concept of Stack,LIFO,Fifo,

  • 2. Unit III Stacks and Queues COs Mapped – CO2, CO5 • Concept of stack and queues as ADT, • Implementation of stacks using sequential and linked organization, • linear queue, • circular queue using sequential and linked organization, • Priority Queue, • Deque, • Application of stack for expression conversion, evaluation, recursion and backtracking • Application of queue in job scheduling
  • 3. What is a Stack? • A Stack is a linear data structure that follows the LIFO (Last-In-First-Out) principle. • Stack has one end, whereas the Queue has two ends (front and rear). • It contains only one pointer top pointer pointing to the topmost element of the stack.
  • 4. • Whenever an element is added in the stack, it is added on the top of the stack, and the element can be deleted only from the stack. • In other words, a stack can be defined as a container in which insertion and deletion can be done from the one end known as the top of the stack.
  • 5. Some key points related to stack • It is called as stack because it behaves like a real-world stack, piles of books, etc. • A Stack is an abstract data type with a pre- defined capacity, which means that it can store the elements of a limited size. • It is a data structure that follows some order to insert and delete the elements, and that order can be LIFO or FILO.
  • 6. Working of Stack • Stack works on the LIFO pattern. As we can observe in the below figure there are five memory blocks in the stack; therefore, the size of the stack is 5. • Suppose we want to store the elements in a stack and let's assume that stack is empty. We have taken the stack of size 5 as shown below in which we are pushing the elements one by one until the stack becomes full.
  • 7.
  • 8. • Since our stack is full as the size of the stack is 5. • In the above cases, we can observe that it goes from the top to the bottom when we were entering the new element in the stack. • The stack gets filled up from the bottom to the top.
  • 9. • When we perform the delete operation on the stack, there is only one way for entry and exit as the other end is closed. • It follows the LIFO pattern, which means that the value entered first will be removed last. In the above case, the value 5 is entered first, so it will be removed only after the deletion of all the other elements.
  • 10. Stack ADT in Data Structures • Let us now see the data object, operations and axioms associated with stack. • Any sets of elements that are of the same data type can be used as a data object for stack • E.g.stack of integers, stack of students etc.
  • 11.
  • 12.
  • 13. Stack ADT in Data Structures • The abstract datatype is special kind of datatype, whose behavior is defined by a set of values and set of operations. • The keyword “Abstract” is used as we can use these datatypes, we can perform different operations. • But how those operations are working that is totally hidden from the user. • The ADT is made of with primitive datatypes, but operation logics are hidden.
  • 14. Here we will see the stack ADT. These are few operations or functions of the Stack ADT. 1. isFull(), This is used to check whether stack is full or not 2. isEmpry(), This is used to check whether stack is empty or not 3. push(x), This is used to push x into the stack 4. pop(), This is used to delete one element from top of the stack 5. peek(), This is used to get the top most element of the stack 6. size(), this function is used to get number of elements present into the stack
  • 15. Standard Stack Operations The following are some common operations implemented on the stack: 1. push(): When we insert an element in a stack then the operation is known as a push. If the stack is full then the overflow condition occurs. 2. pop(): When we delete an element from the stack, the operation is known as a pop. If the stack is empty means that no element exists in the stack, this state is known as an underflow state. 3. isEmpty(): It determines whether the stack is empty or not. 4. isFull(): It determines whether the stack is full or not.' 5. peek(): It returns the element at the given position. 6. count(): It returns the total number of elements available in a stack. 7. change(): It changes the element at the given position. 8. display(): It prints all the elements available in the stack.