Queues - PowerPoint PPT Presentation

About This Presentation
Title:

Queues

Description:

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 ... – PowerPoint PPT presentation

Number of Views:107
Avg rating:3.0/5.0
Slides: 14
Provided by: Prefe123
Learn more at: https://people.hsc.edu
Category:
Tags: queues

less

Transcript and Presenter's Notes

Title: Queues


1
Queues
  • Lecture 30
  • Mon, Apr 10, 2006

2
Topics
  • Queues
  • Queue ADT
  • Queue implementation

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.

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.

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.

6
Queue Constructors
  • Construct an empty queue.
  • Construct a copy of the specified queue.

Queue()
Queue(const Queue q)
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
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()
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
10
Other Member Functions
  • Determine whether the queue has a valid structure.

void isValid() const
11
Non-Member Functions
  • Read a queue from the specified input stream.
  • Write a queue to the specified output stream.

istream operatorgtgt(istream in, Queue q)
ostream operatorltlt(ostream out, const Queue q)
12
Queue Implementation
  • Choose an appropriate List class as a base class.
  • Good choices
  • CircArrayList
  • LinkedListwTail
  • DoublyLinkedList
  • CircLinkedList

13
Queue Implementation
  • Bad choices
  • ArrayList
  • LinkedList
  • Use private inheritance to enforce the Queue
    structure on the List.
Write a Comment
User Comments (0)
About PowerShow.com