SlideShare a Scribd company logo
Stacks
A Stack is a Last In First Out (LIFO) data structure. It supports two basic operations
called push and pop. The push operation adds an element at the top of the stack,
and the pop operation removes an element from the top of the stack.
 Java provides a Stack class which models the Stack data structure. The
Stack class is part of Java’s collections framework.
 What can we do with a stack?
 push - place an item on the stack
 peek - Look at the item on top of the stack, but do not remove it
 pop - Look at the item on top of the stack and remove it
A
X
R
C
push(M)
A
X
R
C
M
item = pop()
item = M
A
X
R
C
 Real life examples –
 Pile of plates on a dinner table.
 Browser uses stack to maintain back and forth movement of user on the
pages of a website.
 To reverse a word You push a given word to stack - letter by letter - and
then pop letters from the stack.
 Backtracking
 Suppose we are finding a path for solving maze problem. We choose a
path and after following it we realize that it is wrong. Now we need to go
back to the beginning of the path to start with new path. This can be
done with the help of stack.
 Expression Evaluation
 Stack is used to evaluate prefix, postfix and infix expressions.
 Expression Conversion
 An expression can be represented in prefix, postfix or infix notation. Stack
can be used to convert one form of expression to another.
 For Example:
 Input : Prefix : *+AB-CD
 Output : Infix : ((A+B)*(C-D))
https://codeburst.io/conversion-of-infix-expression-to-postfix-expression-using-
stack-data-structure-3faf9c212ab8
What is a Queue?
 What is a queue?
 A data structure of ordered items such that items can be inserted only at one end and
removed at the other end.
 A queue is called a FIFO (First in-First out) data structure.
 Java provides a Queue interface which is part of Java’s collections framework.
 Example
 A line at the supermarket
 What can we do with a queue?
 Enqueue - Add an item to the queue
 Dequeue - Remove an item from the queue
 What are some applications of queues?
 online waiting system
 Input/Output processing
 Queueing of packets for delivery in networks

More Related Content

PDF
PPT
Difference between stack and queue
PPTX
Stack and queue
PDF
Stacks and queues
PPTX
Stack and Queue by M.Gomathi Lecturer
PPTX
My lecture stack_queue_operation
PPTX
stack & queue
PDF
What is Tuple in python? | Python Tuple Tutorial | Edureka
Difference between stack and queue
Stack and queue
Stacks and queues
Stack and Queue by M.Gomathi Lecturer
My lecture stack_queue_operation
stack & queue
What is Tuple in python? | Python Tuple Tutorial | Edureka

What's hot (20)

PPTX
Data structure day3
PPT
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
PPT
Queue Data Structure
PPT
Lecture7
PPTX
PDF
Python Collections Tutorial | Edureka
PPT
Lecture5
PPTX
PDF
PPTX
Stack converted
PPTX
Ds stack & queue
PPT
DATA STRUCTURES
PPTX
Stack and Queue
PPTX
Stack Data structure
PPTX
Queues in data structures
PPT
Queue data structure
PPTX
Stack project
PPSX
Data structure stack&queue basics
PPT
Stacks
Data structure day3
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Queue Data Structure
Lecture7
Python Collections Tutorial | Edureka
Lecture5
Stack converted
Ds stack & queue
DATA STRUCTURES
Stack and Queue
Stack Data structure
Queues in data structures
Queue data structure
Stack project
Data structure stack&queue basics
Stacks
Ad

Similar to Stack & Queue (20)

PPTX
Stacks And Queues and representation .pptx
PPT
Stacks overview with its applications
PPTX
Stacks Data structure.pptx
PPTX
CH4.pptx
PDF
stack 1.pdf
PPTX
Stack and its operations, Queue and its operations
PPTX
Introduction to information about Data Structure.pptx
PPTX
dsppt-141121224848-conversion01 (1).pptx
PPTX
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
PPTX
5.-Stacks.pptx
PPTX
Stack & Queue
PPT
stack.ppt
PDF
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
PPTX
Stack and its operations
PPTX
Data Structures Stack and Queue Data Structures
DOCX
Stacks in data structure
PPT
Unit i(dsc++)
PDF
Introduction and BackgroundIn recent lectures we discussed usi.pdf
PDF
computer notes - Conversion from infix to postfix
PPTX
Data structure Stack
Stacks And Queues and representation .pptx
Stacks overview with its applications
Stacks Data structure.pptx
CH4.pptx
stack 1.pdf
Stack and its operations, Queue and its operations
Introduction to information about Data Structure.pptx
dsppt-141121224848-conversion01 (1).pptx
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
5.-Stacks.pptx
Stack & Queue
stack.ppt
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
Stack and its operations
Data Structures Stack and Queue Data Structures
Stacks in data structure
Unit i(dsc++)
Introduction and BackgroundIn recent lectures we discussed usi.pdf
computer notes - Conversion from infix to postfix
Data structure Stack
Ad

More from SAGARDAVE29 (12)

PPTX
Graphical User Interface (GUI)
PPTX
ArrayList in JAVA
PPTX
Exception Handling
PPTX
JAVA Multithreading
PPTX
ArrayList in JAVA
PPTX
Threads in JAVA
PPTX
Exception handling
PPTX
More oop in java
PPTX
Coding Style & Tips for JAVA
PPTX
Some Important Methods in JAVA
PPTX
Recursion
PPTX
Inheritance & Polymorphism
Graphical User Interface (GUI)
ArrayList in JAVA
Exception Handling
JAVA Multithreading
ArrayList in JAVA
Threads in JAVA
Exception handling
More oop in java
Coding Style & Tips for JAVA
Some Important Methods in JAVA
Recursion
Inheritance & Polymorphism

Recently uploaded (20)

PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Insiders guide to clinical Medicine.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Computing-Curriculum for Schools in Ghana
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Institutional Correction lecture only . . .
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
01-Introduction-to-Information-Management.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Microbial diseases, their pathogenesis and prophylaxis
Insiders guide to clinical Medicine.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Computing-Curriculum for Schools in Ghana
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
VCE English Exam - Section C Student Revision Booklet
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
102 student loan defaulters named and shamed – Is someone you know on the list?
Institutional Correction lecture only . . .
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
01-Introduction-to-Information-Management.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
O5-L3 Freight Transport Ops (International) V1.pdf

Stack & Queue

  • 1. Stacks A Stack is a Last In First Out (LIFO) data structure. It supports two basic operations called push and pop. The push operation adds an element at the top of the stack, and the pop operation removes an element from the top of the stack.
  • 2.  Java provides a Stack class which models the Stack data structure. The Stack class is part of Java’s collections framework.
  • 3.  What can we do with a stack?  push - place an item on the stack  peek - Look at the item on top of the stack, but do not remove it  pop - Look at the item on top of the stack and remove it A X R C push(M) A X R C M item = pop() item = M A X R C
  • 4.  Real life examples –  Pile of plates on a dinner table.  Browser uses stack to maintain back and forth movement of user on the pages of a website.  To reverse a word You push a given word to stack - letter by letter - and then pop letters from the stack.  Backtracking  Suppose we are finding a path for solving maze problem. We choose a path and after following it we realize that it is wrong. Now we need to go back to the beginning of the path to start with new path. This can be done with the help of stack.
  • 5.  Expression Evaluation  Stack is used to evaluate prefix, postfix and infix expressions.  Expression Conversion  An expression can be represented in prefix, postfix or infix notation. Stack can be used to convert one form of expression to another.  For Example:  Input : Prefix : *+AB-CD  Output : Infix : ((A+B)*(C-D)) https://codeburst.io/conversion-of-infix-expression-to-postfix-expression-using- stack-data-structure-3faf9c212ab8
  • 6. What is a Queue?
  • 7.  What is a queue?  A data structure of ordered items such that items can be inserted only at one end and removed at the other end.  A queue is called a FIFO (First in-First out) data structure.  Java provides a Queue interface which is part of Java’s collections framework.
  • 8.  Example  A line at the supermarket  What can we do with a queue?  Enqueue - Add an item to the queue  Dequeue - Remove an item from the queue  What are some applications of queues?  online waiting system  Input/Output processing  Queueing of packets for delivery in networks