SlideShare a Scribd company logo
 Chapter 8 introduces the
queue data type.
 Several example
applications of queues are
given in that chapter.
 This presentation describes
the queue operations and
two ways to implement a
queue.
Using a Queue
Data Structures
and Other Objects
Using C++
The Queue Operations
 A queue is like a line
of people waiting for a
bank teller. The queue
has a front and a rear.
$ $
Front
Rear
The Queue Operations
 New people must enter the queue at the
rear. The C++ queue class calls this a
push, although it is usually called an
enqueue operation.
$ $
Front
Rear
The Queue Operations
 When an item is taken from the queue,
it always comes from the front. The
C++ queue calls this a pop, although it
is usually called a dequeue operation.
$ $
Front
Rear
The Queue Class
 The C++ standard
template library has
a queue template
class.
 The template
parameter is the
type of the items
that can be put in
the queue.
template <class Item>
class queue<Item>
{
public:
queue( );
void push(const Item& entry);
void pop( );
bool empty( ) const;
Item front( ) const;
…
Array Implementation
 A queue can be implemented with an array, as
shown here. For example, this queue contains the
integers 4 (at the front), 8 and 6 (at the rear).
[ 0 ] [1] [ 2 ] [ 3 ] [ 4 ] [ 5 ] . . .
An array of integers
to implement a
queue of integers
4 8 6
We don't care what's in
this part of the array.
Array Implementation
 The easiest implementation also keeps
track of the number of items in the
queue and the index of the first
element (at the front of the queue), the
last element (at the rear).
[ 0 ] [1] [ 2 ] [ 3 ] [ 4 ] [ 5 ] . . .
4 8 6
size
3
first
0
last
2
A Dequeue Operation
 When an element leaves the queue,
size is decremented, and first changes,
too.
[ 0 ] [1] [ 2 ] [ 3 ] [ 4 ] [ 5 ] . . .
4 8 6
size
2
first
1
last
2
An Enqueue Operation
 When an element enters the queue,
size is incremented, and last changes,
too.
[ 0 ] [1] [ 2 ] [ 3 ] [ 4 ] [ 5 ] . . .
2
8 6
size
3
first
1
last
3
At the End of the Array
 There is special behavior at the end of
the array. For example, suppose we
want to add a new element to this
queue, where the last index is [5]:
[ 0 ] [1] [ 2 ] [ 3 ] [ 4 ] [ 5 ]
2 1
6
size
3
first
3
last
5
At the End of the Array
 The new element goes at the front of
the array (if that spot isn’t already
used):
[ 0 ] [1] [ 2 ] [ 3 ] [ 4 ] [ 5 ]
2 1
6
size
4
first
3
last
0
4
Array Implementation
 Easy to implement
 But it has a limited capacity with a fixed array
 Or you must use a dynamic array for an
unbounded capacity
 Special behavior is needed when the rear reaches
the end of the array.
[ 0 ] [1] [ 2 ] [ 3 ] [ 4 ] [ 5 ] . . .
4 8 6
size
3
first
0
last
2
Linked List Implementation
10
15
7
null
13
 A queue can also be
implemented with a linked list
with both a head and a tail
pointer.
head_ptr
tail_ptr
Linked List Implementation
10
15
7
null
13
 Which end do you think is the
front of the queue? Why?
head_ptr
tail_ptr
Linked List Implementation
10
15
7
null
head_ptr
13
 The head_ptr points to the front
of the list.
 Because it is harder to remove
items from the tail of the list.
tail_ptr
Front
Rear
 Like stacks, queues have many applications.
 Items enter a queue at the rear and leave a
queue at the front.
 Queues can be implemented using an array
or using a linked list.
Summary
THE END
Presentation copyright 2010, Addison Wesley Longman,
For use with Data Structures and Other Objects Using C++
by Michael Main and Walter Savitch.
Some artwork in the presentation is used with permission from Presentation Task Force
(copyright New Vision Technologies Inc) and Corel Gallery Clipart Catalog (copyright
Corel Corporation, 3G Graphics Inc, Archive Arts, Cartesia Software, Image Club
Graphics Inc, One Mile Up Inc, TechPool Studios, Totem Graphics Inc).
Students and instructors who use Data Structures and Other Objects Using C++ are welcome
to use this presentation however they see fit, so long as this copyright notice remains
intact.

More Related Content

PPT
Queue
Nabeel Ahsen
 
PPT
Queue Data Structure
Lovely Professional University
 
PPSX
Data structure stack&queue basics
Selvin Josy Bai Somu
 
PPTX
queue & its applications
somendra kumar
 
PDF
Queues
Hareem Aslam
 
PPTX
Queue ppt
SouravKumar328
 
PPT
Queue in Data Structure
Muhazzab Chouhadry
 
Queue Data Structure
Lovely Professional University
 
Data structure stack&queue basics
Selvin Josy Bai Somu
 
queue & its applications
somendra kumar
 
Queues
Hareem Aslam
 
Queue ppt
SouravKumar328
 
Queue in Data Structure
Muhazzab Chouhadry
 

What's hot (20)

PPT
Queue AS an ADT (Abstract Data Type)
Self-Employed
 
PPT
Queue data structure
anooppjoseph
 
PPTX
Queues
Ashim Lamichhane
 
PPTX
My lectures circular queue
Senthil Kumar
 
PPSX
Data Structure (Queue)
Adam Mukharil Bachtiar
 
PDF
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
Balwant Gorad
 
PPTX
Queue
Raj Sarode
 
PDF
Queue as data_structure
eShikshak
 
PPT
Queue Data Structure
Zidny Nafan
 
PPTX
Stack Data structure
B Liyanage Asanka
 
PDF
Sorting
Budditha Hettige
 
PDF
Data Structures 01
Budditha Hettige
 
PPTX
Review of basic data structures
Deepa Rani
 
PPT
Priority queues
Priyanka Rana
 
PPTX
Queue in Data Structure
Janki Shah
 
PPTX
Unit 4 queue
Dabbal Singh Mahara
 
PPTX
Stack and queue
CHANDAN KUMAR
 
PDF
Link List
Budditha Hettige
 
Queue AS an ADT (Abstract Data Type)
Self-Employed
 
Queue data structure
anooppjoseph
 
My lectures circular queue
Senthil Kumar
 
Data Structure (Queue)
Adam Mukharil Bachtiar
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
Balwant Gorad
 
Queue
Raj Sarode
 
Queue as data_structure
eShikshak
 
Queue Data Structure
Zidny Nafan
 
Stack Data structure
B Liyanage Asanka
 
Data Structures 01
Budditha Hettige
 
Review of basic data structures
Deepa Rani
 
Priority queues
Priyanka Rana
 
Queue in Data Structure
Janki Shah
 
Unit 4 queue
Dabbal Singh Mahara
 
Stack and queue
CHANDAN KUMAR
 
Link List
Budditha Hettige
 
Ad

Similar to basics of queues (20)

PPT
Lecture 2d queues
Victor Palmar
 
PDF
Queue ADT for data structure for computer
abinathsabi
 
PPTX
Mca ii dfs u-3 linklist,stack,queue
Rai University
 
PPT
Lec-07 Queues.ppt queues introduction to queue
AmsaAzeem
 
PPTX
Bsc cs ii dfs u-2 linklist,stack,queue
Rai University
 
PPTX
Bca ii dfs u-2 linklist,stack,queue
Rai University
 
PPT
Queue data structure
Mekk Mhmd
 
PPTX
Queue
Ayaz Akhtar
 
PPTX
Queues_0748555555555555555555555526.pptx
nailapp2023
 
PPTX
Queue Data Structure with detailed explanation
shanmugapriyacsecs
 
PPT
Queues in C++ detailed explanation and examples .ppt
Jamiluddin39
 
PPTX
The presention is about the queue data structure
gaurav77712
 
PPT
Data Structure Lecture 4
Teksify
 
PPTX
Dynamic Queue.pptx
IkramSabir4
 
PPTX
Queues
Syed Zaid Irshad
 
PPTX
Data Structures - Lecture 6 [queues]
Muhammad Hammad Waseem
 
PPTX
Fundamentals of Data Structure and Queues
Bogiri Nagaraju
 
PPTX
Stack and Queue
Apurbo Datta
 
PPTX
Queue
Abdur Rehman
 
PPTX
Queue and its operations
V.V.Vanniaperumal College for Women
 
Lecture 2d queues
Victor Palmar
 
Queue ADT for data structure for computer
abinathsabi
 
Mca ii dfs u-3 linklist,stack,queue
Rai University
 
Lec-07 Queues.ppt queues introduction to queue
AmsaAzeem
 
Bsc cs ii dfs u-2 linklist,stack,queue
Rai University
 
Bca ii dfs u-2 linklist,stack,queue
Rai University
 
Queue data structure
Mekk Mhmd
 
Queues_0748555555555555555555555526.pptx
nailapp2023
 
Queue Data Structure with detailed explanation
shanmugapriyacsecs
 
Queues in C++ detailed explanation and examples .ppt
Jamiluddin39
 
The presention is about the queue data structure
gaurav77712
 
Data Structure Lecture 4
Teksify
 
Dynamic Queue.pptx
IkramSabir4
 
Data Structures - Lecture 6 [queues]
Muhammad Hammad Waseem
 
Fundamentals of Data Structure and Queues
Bogiri Nagaraju
 
Stack and Queue
Apurbo Datta
 
Queue and its operations
V.V.Vanniaperumal College for Women
 
Ad

Recently uploaded (20)

PPTX
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PDF
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
PDF
The Picture of Dorian Gray summary and depiction
opaliyahemel
 
PPTX
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
PDF
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PPTX
Trends in pediatric nursing .pptx
AneetaSharma15
 
PDF
RA 12028_ARAL_Orientation_Day-2-Sessions_v2.pdf
Seven De Los Reyes
 
PPTX
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
PDF
Types of Literary Text: Poetry and Prose
kaelandreabibit
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PDF
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
DOCX
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
PPTX
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
PPTX
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
PPTX
CDH. pptx
AneetaSharma15
 
PPTX
FSSAI (Food Safety and Standards Authority of India) & FDA (Food and Drug Adm...
Dr. Paindla Jyothirmai
 
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
The Picture of Dorian Gray summary and depiction
opaliyahemel
 
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
Trends in pediatric nursing .pptx
AneetaSharma15
 
RA 12028_ARAL_Orientation_Day-2-Sessions_v2.pdf
Seven De Los Reyes
 
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
Types of Literary Text: Poetry and Prose
kaelandreabibit
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
CDH. pptx
AneetaSharma15
 
FSSAI (Food Safety and Standards Authority of India) & FDA (Food and Drug Adm...
Dr. Paindla Jyothirmai
 

basics of queues

  • 1.  Chapter 8 introduces the queue data type.  Several example applications of queues are given in that chapter.  This presentation describes the queue operations and two ways to implement a queue. Using a Queue Data Structures and Other Objects Using C++
  • 2. The Queue Operations  A queue is like a line of people waiting for a bank teller. The queue has a front and a rear. $ $ Front Rear
  • 3. The Queue Operations  New people must enter the queue at the rear. The C++ queue class calls this a push, although it is usually called an enqueue operation. $ $ Front Rear
  • 4. The Queue Operations  When an item is taken from the queue, it always comes from the front. The C++ queue calls this a pop, although it is usually called a dequeue operation. $ $ Front Rear
  • 5. The Queue Class  The C++ standard template library has a queue template class.  The template parameter is the type of the items that can be put in the queue. template <class Item> class queue<Item> { public: queue( ); void push(const Item& entry); void pop( ); bool empty( ) const; Item front( ) const; …
  • 6. Array Implementation  A queue can be implemented with an array, as shown here. For example, this queue contains the integers 4 (at the front), 8 and 6 (at the rear). [ 0 ] [1] [ 2 ] [ 3 ] [ 4 ] [ 5 ] . . . An array of integers to implement a queue of integers 4 8 6 We don't care what's in this part of the array.
  • 7. Array Implementation  The easiest implementation also keeps track of the number of items in the queue and the index of the first element (at the front of the queue), the last element (at the rear). [ 0 ] [1] [ 2 ] [ 3 ] [ 4 ] [ 5 ] . . . 4 8 6 size 3 first 0 last 2
  • 8. A Dequeue Operation  When an element leaves the queue, size is decremented, and first changes, too. [ 0 ] [1] [ 2 ] [ 3 ] [ 4 ] [ 5 ] . . . 4 8 6 size 2 first 1 last 2
  • 9. An Enqueue Operation  When an element enters the queue, size is incremented, and last changes, too. [ 0 ] [1] [ 2 ] [ 3 ] [ 4 ] [ 5 ] . . . 2 8 6 size 3 first 1 last 3
  • 10. At the End of the Array  There is special behavior at the end of the array. For example, suppose we want to add a new element to this queue, where the last index is [5]: [ 0 ] [1] [ 2 ] [ 3 ] [ 4 ] [ 5 ] 2 1 6 size 3 first 3 last 5
  • 11. At the End of the Array  The new element goes at the front of the array (if that spot isn’t already used): [ 0 ] [1] [ 2 ] [ 3 ] [ 4 ] [ 5 ] 2 1 6 size 4 first 3 last 0 4
  • 12. Array Implementation  Easy to implement  But it has a limited capacity with a fixed array  Or you must use a dynamic array for an unbounded capacity  Special behavior is needed when the rear reaches the end of the array. [ 0 ] [1] [ 2 ] [ 3 ] [ 4 ] [ 5 ] . . . 4 8 6 size 3 first 0 last 2
  • 13. Linked List Implementation 10 15 7 null 13  A queue can also be implemented with a linked list with both a head and a tail pointer. head_ptr tail_ptr
  • 14. Linked List Implementation 10 15 7 null 13  Which end do you think is the front of the queue? Why? head_ptr tail_ptr
  • 15. Linked List Implementation 10 15 7 null head_ptr 13  The head_ptr points to the front of the list.  Because it is harder to remove items from the tail of the list. tail_ptr Front Rear
  • 16.  Like stacks, queues have many applications.  Items enter a queue at the rear and leave a queue at the front.  Queues can be implemented using an array or using a linked list. Summary
  • 17. THE END Presentation copyright 2010, Addison Wesley Longman, For use with Data Structures and Other Objects Using C++ by Michael Main and Walter Savitch. Some artwork in the presentation is used with permission from Presentation Task Force (copyright New Vision Technologies Inc) and Corel Gallery Clipart Catalog (copyright Corel Corporation, 3G Graphics Inc, Archive Arts, Cartesia Software, Image Club Graphics Inc, One Mile Up Inc, TechPool Studios, Totem Graphics Inc). Students and instructors who use Data Structures and Other Objects Using C++ are welcome to use this presentation however they see fit, so long as this copyright notice remains intact.