1 / 12

Queues

Queues. Lecture 30 Mon, Apr 9, 2007. 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.

sbarlow
Download Presentation

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 9, 2007

  2. 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

  3. 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

  4. 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

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

  6. 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

  7. 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

  8. 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

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

  10. 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

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

  12. Queue Implementation • Bad choices • ArrayList • LinkedList Queues

More Related