Notes 11 - Week 11: Queues Def: A queue is a list that can...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Week 11: Queues Def: A queue is a list that can grow at the tail and shrink at the head A waiting list FIFO “first-in, first-out” (same as “last-in, last-out”) Restrict add and remove to insertTail enqueue(newEntry) deleteHead dequeue() Removing all entries provides a chronological ordering. Task 1: Review the ADT on page 581 and interface on page 582 Example : QueueInterface myQ = new linkedQueue; myQ.dequeue() // could return null or call an exception myQ.enqueue("Mercury"); myQ.enqueue("Venus"); myQ.enqueue("Mars"); String front1 = (String) myQ.getFront(); myQ.dequeue(); String front2 = (String) myQ.dequeue(); myQ.enqueue("Mars"); String front3 = (String) myQ.dequeue(); System.out.println(front1 + front2 + front3); Output: MercuryVenusMars and the queue still contains Mars Task 2: Do #1 on page 583 and check your answer in the appendix. Some uses of Queues Queuing behavior (waiting lines) Example: Given job W A I T S arrival time 5 6 8 9 13 service time 3 3 3 3 3 Time 0 5 6 8 9 11 13 14 17 20
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

Notes 11 - Week 11: Queues Def: A queue is a list that can...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online