lecture19-july27 - Lecture 19 Announcements The Collection...

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

View Full Document Right Arrow Icon
7/27/09 1 Lecture 19 Announcements The Collection Hierarchy AbstractQueue PriorityQueue + Application: A Print Queue • Operating systems use queues to – Track of tasks waiting for a scarce resource – To ensure that the tasks are carried out in the order that they were generated • Print queue: printing is much slower than the process of selecting pages to print and so a queue is used • Important use of queues is I/O scheduling – Use buffers in memory to improve program execution – Because devices and the CPU run at different speeds Buffer arranged in FIFO structure ifstream inStream; • Also times when insertions, deletions must be made from both ends – Consider a scrolling window on the screen • This requires a double ended queue – Called a deque (pronounced "deck") • Consider a keyboard buffer – Acts as a queue – But elements may be removed from the back of the queue with backspace key
Background image of page 1

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

View Full Document Right Arrow Icon
7/27/09 2 • Queues used to schedule tasks within an operating system •Job moves from disk to ready queue • Ready queue may actually be a priority queue … job may get to "cut to the front of line" based on its priority Queue Scheduler Example // output the day's appointment schedlule System.out.println ("Appointment Schedule”); while (!apptQ.isempty()) { appt = apptQ.front(); // remove the next appointment & output it apptQ.dequeue ( ); System.out.println (appt.interviewTime + " ” + appt.interviewName); } } /* the program creates and outputs the interview schedule for a personnel director. The schedule is constructed using a queue of appointment times and names by reading the times from the keyboard. By then cycling through the queue, the appointment times & names are output. Scanner for input. */ // queue to hold appointment info for applicants MyQueue <ApptInfo> apptQ = new MyQueue <ApptInfo> ( ); ApptInfo appt = new ApptInfo ( ) // build the schedule from user inputs // construct the queue until input is 17:00 or later do { // prompt for the next interview information System.out.println( ”input the next interview:” + “time & name ”); appt.interviewTime = console.nextInt ( ); ; appt.interviewName = console.nextLine ( ); ; // put the interview info on the queue apptQ.enqueue (appt); } while (appt.interviewTime < 17) class ApptInfo { int interviewTime; // using a simple 24 hour int clock String interviewName; } Application:Simulating Waiting Lines Simulation is used to study the performance of a physical system by using a physical, mathematical, or computer model of the system Simulation allows designers of a new system to estimate the expected performance before building it Simulation can lead to changes in the design that will improve the expected performance of the new system Useful when the real system would be too expensive to build or too
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 8

lecture19-july27 - Lecture 19 Announcements The Collection...

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

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