SlideShare a Scribd company logo
1 of 7
Download to read offline
Queues 3/16/14
1
Queues 1
Queues
© 2014 Goodrich, Tamassia, Goldwasser
Presentation for use with the textbook Data Structures and
Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
and M. H. Goldwasser, Wiley, 2014
Queues 2
The Queue ADT
q  The Queue ADT stores arbitrary
objects
q  Insertions and deletions follow
the first-in first-out scheme
q  Insertions are at the rear of the
queue and removals are at the
front of the queue
q  Main queue operations:
n  enqueue(object): inserts an
element at the end of the
queue
n  object dequeue(): removes and
returns the element at the front
of the queue
q  Auxiliary queue
operations:
n  object first(): returns the
element at the front without
removing it
n  integer size(): returns the
number of elements stored
n  boolean isEmpty(): indicates
whether no elements are
stored
q  Boundary cases:
n  Attempting the execution of
dequeue or first on an
empty queue returns null
© 2014 Goodrich, Tamassia, Goldwasser
Queues 3/16/14
2
Queues 3
Example
Operation 	

 	

 	

Output 	

Q
enqueue(5) – (5)
enqueue(3) – (5, 3)
dequeue() 5 (3)
enqueue(7) – (3, 7)
dequeue() 3 (7)
first() 7 (7)
dequeue() 7 ()
dequeue() null ()
isEmpty() true ()
enqueue(9) – (9)
enqueue(7) – (9, 7)
size() 2 (9, 7)
enqueue(3) – (9, 7, 3)
enqueue(5) – (9, 7, 3, 5)
dequeue() 9 (7, 3, 5)
© 2014 Goodrich, Tamassia, Goldwasser
Queues 4
Applications of Queues
q  Direct applications
n  Waiting lists, bureaucracy
n  Access to shared resources (e.g., printer)
n  Multiprogramming
q  Indirect applications
n  Auxiliary data structure for algorithms
n  Component of other data structures
© 2014 Goodrich, Tamassia, Goldwasser
Queues 3/16/14
3
Queues 5
Array-based Queue
q  Use an array of size N in a circular fashion
q  Two variables keep track of the front and size
f index of the front element
sz number of stored elements
q  When the queue has fewer than N elements, array
location r = (f + sz) mod N is the first empty slot
past the rear of the queue
Q
0 1 2 r
f
normal configuration
Q
0 1 2 f
r
wrapped-around configuration
© 2014 Goodrich, Tamassia, Goldwasser
Queues 6
Queue Operations
q  We use the
modulo operator
(remainder of
division)
Algorithm size()
return sz
Algorithm isEmpty()
return (sz == 0)
Q
0 1 2 r
f
Q
0 1 2 f
r
© 2014 Goodrich, Tamassia, Goldwasser
Queues 3/16/14
4
Queues 7
Queue Operations (cont.)
Algorithm enqueue(o)
if size() = N - 1 then
throw IllegalStateException
else
r ← (f + sz) mod N
Q[r] ← o
sz ← (sz + 1)
q  Operation enqueue
throws an exception if
the array is full
q  This exception is
implementation-
dependent
Q
0 1 2 r
f
Q
0 1 2 f
r
© 2014 Goodrich, Tamassia, Goldwasser
Queues 8
Queue Operations (cont.)
q  Note that operation
dequeue returns null
if the queue is empty
Algorithm dequeue()
if isEmpty() then
return null
else
o ← Q[f]
f ← (f + 1) mod N
sz ← (sz - 1)
return o
Q
0 1 2 r
f
Q
0 1 2 f
r
© 2014 Goodrich, Tamassia, Goldwasser
Queues 3/16/14
5
Queues 9
Queue Interface in Java
q  Java interface
corresponding to
our Queue ADT
q  Assumes that
first() and
dequeue() return
null if queue is
empty
public interface Queue<E> {
int size();
boolean isEmpty();
E first();
void enqueue(E e);
E dequeue();
}
© 2014 Goodrich, Tamassia, Goldwasser
Array-based Implementation
© 2014 Goodrich, Tamassia, Goldwasser 10
Queues
Queues 3/16/14
6
Array-based Implementation (2)
© 2014 Goodrich, Tamassia, Goldwasser 11
Queues
Comparison to java.util.Queue
q  Our Queue methods and corresponding
methods of java.util.Queue:
© 2014 Goodrich, Tamassia, Goldwasser 12
Queues
Queues 3/16/14
7
Queues 13
Application: Round Robin Schedulers
q  We can implement a round robin scheduler using a
queue Q by repeatedly performing the following
steps:
1.  e = Q.dequeue()
2.  Service element e
3.  Q.enqueue(e)
© 2014 Goodrich, Tamassia, Goldwasser
Shared
Service
Queue
Enqueue
Dequeue

More Related Content

What's hot

03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays
tameemyousaf
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
Senthil Kumar
 
Data structure lecture7
Data structure lecture7Data structure lecture7
Data structure lecture7
Kumar
 

What's hot (19)

Stack and its operations
Stack and its operationsStack and its operations
Stack and its operations
 
Stacks and Queue - Data Structures
Stacks and Queue - Data StructuresStacks and Queue - Data Structures
Stacks and Queue - Data Structures
 
Stack
StackStack
Stack
 
Stack
StackStack
Stack
 
Stacks, Queues, Deques
Stacks, Queues, DequesStacks, Queues, Deques
Stacks, Queues, Deques
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
 
Unit 4 queue
Unit   4 queueUnit   4 queue
Unit 4 queue
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
Queue
QueueQueue
Queue
 
Stacks
StacksStacks
Stacks
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Data structure lecture7
Data structure lecture7Data structure lecture7
Data structure lecture7
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Stack - Data Structure
Stack - Data StructureStack - Data Structure
Stack - Data Structure
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 
2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS
 
Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)
 

Similar to Queues-handouts

queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbbqueuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
RAtna29
 
Lecture 4 - List, Stack, Queues, Deques.pdf
Lecture 4 - List, Stack, Queues, Deques.pdfLecture 4 - List, Stack, Queues, Deques.pdf
Lecture 4 - List, Stack, Queues, Deques.pdf
ssuser400105
 

Similar to Queues-handouts (20)

Dynamic Queue.pptx
Dynamic Queue.pptxDynamic Queue.pptx
Dynamic Queue.pptx
 
Lec3
Lec3Lec3
Lec3
 
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbbqueuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
 
Queue implementation
Queue implementationQueue implementation
Queue implementation
 
Queue
QueueQueue
Queue
 
Queue
QueueQueue
Queue
 
Lec3
Lec3Lec3
Lec3
 
Unit 5 dsa QUEUE
Unit 5 dsa QUEUEUnit 5 dsa QUEUE
Unit 5 dsa QUEUE
 
Lecture 4 - List, Stack, Queues, Deques.pdf
Lecture 4 - List, Stack, Queues, Deques.pdfLecture 4 - List, Stack, Queues, Deques.pdf
Lecture 4 - List, Stack, Queues, Deques.pdf
 
Data Structure Lecture 4
Data Structure Lecture 4Data Structure Lecture 4
Data Structure Lecture 4
 
Queue
QueueQueue
Queue
 
The Art of Java Type Patterns
The Art of Java Type PatternsThe Art of Java Type Patterns
The Art of Java Type Patterns
 
Queue
QueueQueue
Queue
 
Algo>Queues
Algo>QueuesAlgo>Queues
Algo>Queues
 
Algorithms explained
Algorithms explainedAlgorithms explained
Algorithms explained
 
Unit – iv queue
Unit – iv    queueUnit – iv    queue
Unit – iv queue
 
(chapter 9) A Concise and Practical Introduction to Programming Algorithms in...
(chapter 9) A Concise and Practical Introduction to Programming Algorithms in...(chapter 9) A Concise and Practical Introduction to Programming Algorithms in...
(chapter 9) A Concise and Practical Introduction to Programming Algorithms in...
 
2 b queues
2 b queues2 b queues
2 b queues
 
Chap11alg
Chap11algChap11alg
Chap11alg
 
Chap11alg
Chap11algChap11alg
Chap11alg
 

More from Fajar Baskoro

Membangun aplikasi mobile dengan Appsheet
Membangun aplikasi mobile dengan AppsheetMembangun aplikasi mobile dengan Appsheet
Membangun aplikasi mobile dengan Appsheet
Fajar Baskoro
 

More from Fajar Baskoro (20)

Generasi Terampil Digital Skill-2023.pptx
Generasi Terampil Digital Skill-2023.pptxGenerasi Terampil Digital Skill-2023.pptx
Generasi Terampil Digital Skill-2023.pptx
 
Cara Membuat Kursus Online Wordpress-tutorstarter
Cara Membuat Kursus Online Wordpress-tutorstarterCara Membuat Kursus Online Wordpress-tutorstarter
Cara Membuat Kursus Online Wordpress-tutorstarter
 
PPT-Kick Off Double Track 2024 melaksanakan Festival Ramadhan
PPT-Kick Off Double Track 2024 melaksanakan Festival RamadhanPPT-Kick Off Double Track 2024 melaksanakan Festival Ramadhan
PPT-Kick Off Double Track 2024 melaksanakan Festival Ramadhan
 
Buku Inovasi 2023 - 2024 konsep capaian KUS
Buku Inovasi 2023 - 2024 konsep capaian  KUSBuku Inovasi 2023 - 2024 konsep capaian  KUS
Buku Inovasi 2023 - 2024 konsep capaian KUS
 
Pemaparan Sosialisasi Program Dual Track 2024.pptx
Pemaparan Sosialisasi Program Dual Track 2024.pptxPemaparan Sosialisasi Program Dual Track 2024.pptx
Pemaparan Sosialisasi Program Dual Track 2024.pptx
 
Executive Millennial Entrepreneur Award 2023-1a-1.pdf
Executive Millennial Entrepreneur Award  2023-1a-1.pdfExecutive Millennial Entrepreneur Award  2023-1a-1.pdf
Executive Millennial Entrepreneur Award 2023-1a-1.pdf
 
1-Executive Millennial Entrepreneur Award 2023-1-cetak.pptx
1-Executive Millennial Entrepreneur Award  2023-1-cetak.pptx1-Executive Millennial Entrepreneur Award  2023-1-cetak.pptx
1-Executive Millennial Entrepreneur Award 2023-1-cetak.pptx
 
Executive Millennial Entrepreneur Award 2023-1.pptx
Executive Millennial Entrepreneur Award  2023-1.pptxExecutive Millennial Entrepreneur Award  2023-1.pptx
Executive Millennial Entrepreneur Award 2023-1.pptx
 
Pemrograman Mobile - JetPack Compose1.pptx
Pemrograman Mobile - JetPack Compose1.pptxPemrograman Mobile - JetPack Compose1.pptx
Pemrograman Mobile - JetPack Compose1.pptx
 
Evaluasi KPP Program Dual Track Provinsi Kaltim
Evaluasi KPP Program Dual Track Provinsi KaltimEvaluasi KPP Program Dual Track Provinsi Kaltim
Evaluasi KPP Program Dual Track Provinsi Kaltim
 
foto tenda digital skill program dari sekolah
foto tenda digital skill program dari sekolahfoto tenda digital skill program dari sekolah
foto tenda digital skill program dari sekolah
 
Meraih Peluang di Gig Economy yang cocok bagi remaja
Meraih Peluang di Gig Economy yang cocok bagi remajaMeraih Peluang di Gig Economy yang cocok bagi remaja
Meraih Peluang di Gig Economy yang cocok bagi remaja
 
Membangun aplikasi mobile dengan Appsheet
Membangun aplikasi mobile dengan AppsheetMembangun aplikasi mobile dengan Appsheet
Membangun aplikasi mobile dengan Appsheet
 
epl1.pdf
epl1.pdfepl1.pdf
epl1.pdf
 
user.docx
user.docxuser.docx
user.docx
 
Dtmart.pptx
Dtmart.pptxDtmart.pptx
Dtmart.pptx
 
DualTrack-2023.pptx
DualTrack-2023.pptxDualTrack-2023.pptx
DualTrack-2023.pptx
 
BADGE.pptx
BADGE.pptxBADGE.pptx
BADGE.pptx
 
womenatwork.pdf
womenatwork.pdfwomenatwork.pdf
womenatwork.pdf
 
Transition education to employment.pdf
Transition education to employment.pdfTransition education to employment.pdf
Transition education to employment.pdf
 

Recently uploaded

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
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
QucHHunhnh
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
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
kauryashika82
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Recently uploaded (20)

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
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
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
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
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
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 

Queues-handouts

  • 1. Queues 3/16/14 1 Queues 1 Queues © 2014 Goodrich, Tamassia, Goldwasser Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Queues 2 The Queue ADT q  The Queue ADT stores arbitrary objects q  Insertions and deletions follow the first-in first-out scheme q  Insertions are at the rear of the queue and removals are at the front of the queue q  Main queue operations: n  enqueue(object): inserts an element at the end of the queue n  object dequeue(): removes and returns the element at the front of the queue q  Auxiliary queue operations: n  object first(): returns the element at the front without removing it n  integer size(): returns the number of elements stored n  boolean isEmpty(): indicates whether no elements are stored q  Boundary cases: n  Attempting the execution of dequeue or first on an empty queue returns null © 2014 Goodrich, Tamassia, Goldwasser
  • 2. Queues 3/16/14 2 Queues 3 Example Operation Output Q enqueue(5) – (5) enqueue(3) – (5, 3) dequeue() 5 (3) enqueue(7) – (3, 7) dequeue() 3 (7) first() 7 (7) dequeue() 7 () dequeue() null () isEmpty() true () enqueue(9) – (9) enqueue(7) – (9, 7) size() 2 (9, 7) enqueue(3) – (9, 7, 3) enqueue(5) – (9, 7, 3, 5) dequeue() 9 (7, 3, 5) © 2014 Goodrich, Tamassia, Goldwasser Queues 4 Applications of Queues q  Direct applications n  Waiting lists, bureaucracy n  Access to shared resources (e.g., printer) n  Multiprogramming q  Indirect applications n  Auxiliary data structure for algorithms n  Component of other data structures © 2014 Goodrich, Tamassia, Goldwasser
  • 3. Queues 3/16/14 3 Queues 5 Array-based Queue q  Use an array of size N in a circular fashion q  Two variables keep track of the front and size f index of the front element sz number of stored elements q  When the queue has fewer than N elements, array location r = (f + sz) mod N is the first empty slot past the rear of the queue Q 0 1 2 r f normal configuration Q 0 1 2 f r wrapped-around configuration © 2014 Goodrich, Tamassia, Goldwasser Queues 6 Queue Operations q  We use the modulo operator (remainder of division) Algorithm size() return sz Algorithm isEmpty() return (sz == 0) Q 0 1 2 r f Q 0 1 2 f r © 2014 Goodrich, Tamassia, Goldwasser
  • 4. Queues 3/16/14 4 Queues 7 Queue Operations (cont.) Algorithm enqueue(o) if size() = N - 1 then throw IllegalStateException else r ← (f + sz) mod N Q[r] ← o sz ← (sz + 1) q  Operation enqueue throws an exception if the array is full q  This exception is implementation- dependent Q 0 1 2 r f Q 0 1 2 f r © 2014 Goodrich, Tamassia, Goldwasser Queues 8 Queue Operations (cont.) q  Note that operation dequeue returns null if the queue is empty Algorithm dequeue() if isEmpty() then return null else o ← Q[f] f ← (f + 1) mod N sz ← (sz - 1) return o Q 0 1 2 r f Q 0 1 2 f r © 2014 Goodrich, Tamassia, Goldwasser
  • 5. Queues 3/16/14 5 Queues 9 Queue Interface in Java q  Java interface corresponding to our Queue ADT q  Assumes that first() and dequeue() return null if queue is empty public interface Queue<E> { int size(); boolean isEmpty(); E first(); void enqueue(E e); E dequeue(); } © 2014 Goodrich, Tamassia, Goldwasser Array-based Implementation © 2014 Goodrich, Tamassia, Goldwasser 10 Queues
  • 6. Queues 3/16/14 6 Array-based Implementation (2) © 2014 Goodrich, Tamassia, Goldwasser 11 Queues Comparison to java.util.Queue q  Our Queue methods and corresponding methods of java.util.Queue: © 2014 Goodrich, Tamassia, Goldwasser 12 Queues
  • 7. Queues 3/16/14 7 Queues 13 Application: Round Robin Schedulers q  We can implement a round robin scheduler using a queue Q by repeatedly performing the following steps: 1.  e = Q.dequeue() 2.  Service element e 3.  Q.enqueue(e) © 2014 Goodrich, Tamassia, Goldwasser Shared Service Queue Enqueue Dequeue