07Queues - CS 240 Chapter 7 - Queues CS 240 Chapter 7 -...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS 240 Chapter 7 - Queues CS 240 Chapter 7 - Queues 1Page 1 Chapter 7 Queues The queue abstract data type is essentially a list using the FIFO (first- in-first-out) policy for adding and removing elements. The principal queue operations: Create an empty queue. Copy an existing queue. Destroy a queue. Determine whether a queue is empty. Add a new element to a queue. Remove the least recently added element from a queue. CS 240 Chapter 7 - Queues CS 240 Chapter 7 - Queues 2Page 2 Queue Implementation Alternatives An Array Implementation Positives Avoids pointers (uses front & rear indices) Negatives Wraparound is needed to avoid false overflows Size must be declared in advance A Linked List Implementation Positives Dynamically allocates exactly the right amount of memory Wraparound problem is circumvented Negatives Our friendly neighborhood pointers CS 240 Chapter 7 - Queues CS 240 Chapter 7 - Queues 3Page 3 Array Implementation of Queue // Class declaration file: queue.h // Array implementation of the queue ADT. #ifndef QUEUE_H #include <iostream> using namespace std; typedef int elementType; const MAX_QUEUE_SIZE = 200; class queue { public : // Class constructors queue(); queue( const queue &q); // Member functions bool isEmpty(); void enqueue( const elementType &item); elementType dequeue(); protected : // Data members int front, rear, length; elementType list[MAX_QUEUE_SIZE]; // Member function bool isFull(); }; #define QUEUE_H #endif // Class implementation file: queue.cpp // Array implementation of the queue ADT....
View Full Document

Page1 / 8

07Queues - CS 240 Chapter 7 - Queues CS 240 Chapter 7 -...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online