1 / 7

The Queue

The Queue. Whenever you are asked if you can do a job, tell 'em, "Certainly, I can!" Then get busy and find out how to do it. Theodore Roosevelt. Queue.

doctor
Download Presentation

The Queue

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Queue Whenever you are asked if you can do a job, tell 'em, "Certainly, I can!" Then get busy and find out how to do it. Theodore Roosevelt

  2. Queue • a list (initially empty) of items (of some type) to which items may be added at one end (called the rear) and from which items may be removed at the other end (called the front) • examples • waiting lines • print queues • process queue • behaviour • FIFO ordering • error conditions: • underflow • overflow

  3. Queue Interface • generic (Stores objects of type E) • no requirements • operations: • enter (enqueue, add, insert) • leave (dequeue, remove, delete) • front (head, first) • length (count, size) • empty • exceptions • NoItemException • NoSpaceException

  4. Queue ADTContiguous Implementation • based on variable-sized array • two indices: front & rear • add at rear, remove at front • queue moves towards rear • repositioning on delete: O(n) • circular array • at end of array reuse front • index modulo array size

  5. Queue ADT. • implementation • instance variables • count • constructors • empty state • methods • enter • overflow • increment • leave, front • underflow • length, empty • compute? • empty vs full

  6. Queue ADTLinked Implementation • sequentially-linked structure of items • deletion from front • insertion at end • keep pointer to rear O(1) • length? • keep count else O(n) • comparison with contiguous • all operations O(1) • space tradeoffs

  7. The End

More Related