Lecture8-1 - DataStructures CSCI 132, Spring 2012 Lecture 8...

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

View Full Document Right Arrow Icon
1 Data Structures   CSCI 132, Spring 2012 Lecture 8 Implementing Queues
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 The Circular Model The front and rear are the same as the linear model, except: The queue wraps around when the end of the array is reached. append: add 1 to rear, if off the end of array, rear = 0; assign new item to entry[rear] retrieve: return entry[front] serve: increment front by 1, if off the end of array, front = 0; 0 1 2 3 4 5 6 7 8 9 3 7 1 front rear 8
Background image of page 2
3 Queue Operations A Queue class should have the following methods: append(item) //Add an item to the rear of the queue serve( ) //Delete an item from the front of the queue retrieve( ) //Return value of front item empty() //Return true if queue is empty.
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 The Queue Specification typedef int Queue_entry; const int maxqueue =10 ; //small value for testing class Queue { public: Queue(); bool empty()const; Error_code serve(); Error_code retrieve(Queue_entry &item) const; Error_code append(const Queue_entry &item); private: int count, front, rear; Queue_entry entry [maxqueue ]; };
Background image of page 4
5 Implementing append( ) { }
Background image of page 5

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

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

This document was uploaded on 03/09/2012.

Page1 / 22

Lecture8-1 - DataStructures CSCI 132, Spring 2012 Lecture 8...

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

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