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

View Full Document Right Arrow Icon
DALHOUSIE UNIVERSITY DEPARTMENT OF ENGINEERING MATHEMATICS ENGM2282 ASSIGNMENT # 6, Due Thursday Feb. 18, 2010 1. There is a disadvantage to the implementation of a queue using an array as in the notes. In that implementation, when there are count elements stored in the queue, they occupy postions 0 through count-1 in the array. The start of the queue is position 0 and the last entry in the queue is position count-1 . The get method returns the value at postion 0 and moves all entries down by 1 postion. This shuffling of the array elements makes the queue less efficient than a stack. A faster implementation is to to use two positions: start and end . The entries in the queue are all array entries between start and end-1 . The term "between" is interpreted in the circular sense. That is, if the array is of size max then we think of the next postion after max-1 to be postion 0. With this interpretation, the put method places a new entry at postion end and increments end while the get method returns the entry at postion start and increments start . Increment is understood in the circular sense described above. When start == end the queue is empty but this also happens when the queue is full so we still need to keep track of the number of elements in the queue with the variable count . See for a discussion of circular queue. Implement the methods of the class queue as described. For marking purposes, put the values 1, 2, 3, 4, print the queue, then get 3 times followed by putting the values 5, 6, 7, print the queue again, get twice and print the queue again. The constructor, copy constructor, destructor and operator= are written for you. You only need to write the get, put and show methods. // File: circularqueue.cpp // This program implements a circular queue of integers #include <iostream> #include <fstream> using namespace std; class queue { private: int max; // maximum size of queue int count; // current number of entries in the queue int start; // index of first entry in queue
Background image of page 1

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

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

Page1 / 6


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

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