{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# Assi 6 - DALHOUSIE UNIVERSITY DEPARTMENT OF ENGINEERING...

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

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 http://en.wikipedia.org/wiki/Circular_buffer 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.

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 6

Assi 6 - DALHOUSIE UNIVERSITY DEPARTMENT OF ENGINEERING...

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

View Full Document
Ask a homework question - tutors are online