1 / 13

Queues

Queues. Lecture 30 Mon, Apr 10, 2006. Topics. Queues Queue ADT Queue implementation. Queues. A queue is a List that operates under the principle “first in, first out” (FIFO). New elements are enqueued into the queue. Old elements are dequeued from the queue.

teigra
Télécharger la présentation

Queues

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. Queues Lecture 30 Mon, Apr 10, 2006

  2. Topics • Queues • Queue ADT • Queue implementation Queues

  3. Queues • A queue is a List that operates under the principle “first in, first out” (FIFO). • New elements are enqueued into the queue. • Old elements are dequeued from the queue. • To enforce the FIFO principle, we enqueue and dequeue at opposite ends. Queues

  4. Implementation of Queues • Implement a Queue as a subclass of a List class. • Use pushFront() and popBack(), or • Use pushBack() and popFront(). • Choose a List class for which enqueuing and dequeuing will be efficient. Queues

  5. Private Inheritance • Private inheritance prevents violations of the FIFO principle. • The Queue class has access to all public and protected List functions. • The Queue class user has access only to the queue functions. Queues

  6. Queue Constructors • Construct an empty queue. • Construct a copy of the specified queue. Queue(); Queue(const Queue& q); Queues

  7. Inspectors • Get a copy of the element at the head of the queue. • Get the number of elements in the queue. • Determine whether the queue is empty. T head() const; int size() const; bool isEmpty() const; Queues

  8. Mutators • Enqueue the specified value at the tail of the queue. • Dequeue and return the element at the head of the queue. • Make the queue empty. void enqueue(const T& value); T dequeue(); void makeEmpty(); Queues

  9. Facilitators • Read a queue from the specified input stream. • Write a queue to the specified output stream. void Input(istream& in); void Output(ostream& out) const; Queues

  10. Other Member Functions • Determine whether the queue has a valid structure. void isValid() const; Queues

  11. Non-Member Functions • Read a queue from the specified input stream. • Write a queue to the specified output stream. istream& operator>>(istream& in, Queue& q); ostream& operator<<(ostream& out, const Queue& q); Queues

  12. Queue Implementation • Choose an appropriate List class as a base class. • Good choices • CircArrayList • LinkedListwTail • DoublyLinkedList • CircLinkedList Queues

  13. Queue Implementation • Bad choices • ArrayList • LinkedList • Use private inheritance to enforce the Queue structure on the List. Queues

More Related