Skip to main content

Exercises 29.7 Exercises

1.

Write the enqueue function for the Array Based Queue.
You do not need to worry about the queue being full, but you should correctly handle wrapping back around to 0 when the end index reaches the end of the array.

2.

Write the dequeue function for the Array Based Queue.
Make sure to correctly handle wrapping around to 0 when the start index reaches the end of the array.

3.

Write the full function for the Array Based Queue.
You will need your enqueue and dequeue functions.
Hint.
Remember that there are two cases for detecting when the queue is full. Normally, we just want to know if the end index is one position behind the start index. But, if the start index is at 0, the queue is full if end reaches the last position in the array.

4.

Write the grow function for the Array Based Queue.
It should double the size of the underlying array and copy the existing elements to the new array in the correct order.
You will need your enqueue and dequeue functions.
Hint 1.
You will need to loop from start to end and may need to wrap around while looping.
Hint 2.
You will likely need/want a different counter for the location in the new array. The logic is easiest if you place the elements in the new array starting from 0. They will never need to wrap in the new array.
You have attempted of activities on this page.