Introduction to Programming s4

Introduction to Programming s4

<p>Computer Programming II Instructor: Greg Shaw COP 3337 </p><p>Queues</p><p>I. What is a queue? FIFO and LILO</p><p>1. A queue is an abstract “first-in-first-out” (“FIFO”) data structure. This means that the first item placed in the queue will be the first item removed from it.</p><p>2. “FIFO = LILO” means that a queue is also a “last-in-last-out” (“LILO”) data structure. That is, the last item placed in the queue will be the last item removed from it.</p><p>3. In a queue, generally only the first and the last elements are accessible. Each new item added is placed at the rear of the queue, and the next item to be removed is always the one at the front.</p><p>II. Primitive Queue Operations – append, serve, isEmpty</p><p>1. q.append(obj) ;</p><p> the object obj is appended to the rear of Queue q</p><p>2. var = q.serve() ;</p><p> the object at the front of Queue q is removed and returned</p><p>3. q.isEmpty()</p><p> returns true/false indicating whether Queue q is empty (an empty queue cannot be served)</p><p>III. Examples of Queues</p><p>1. A line of people waiting to buy tickets for an event, or to see a teller in a bank </p><p>2. A bunch of planes circling an airport waiting for clearance to land (Note that it is commonly said that such planes are “stacked up” over the airport. They’re not; they are “queued up.” If they really were stacked up, and new planes kept arriving, then the ones that had been there the longest would begin to run out of fuel and fall from the sky.) 3. A bunch of jobs sent to a network printer to be printed. They will be queued up and printed in the order received.</p><p>4. A bunch of jobs waiting for the processor to give them a “slice of time” in a multitasking operating system</p><p>IV. Priority Queues</p><p>A related data structure is the “priority queue.” In a priority queue, although new arrivals are appended at the rear, the next item served is not necessarily the one at the front. Instead, the items in the queue are ranked according to some criterion, and items are served according to their rank.</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    3 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us