To practice using queues implemented with arrays
For this lab, you will fix our ArrayQueue implementation to do two things. First, you will make it throw an exception when the dequeue method is called on an empty queue. Second, you make the enqueue method resize the queue when it is called on a full queue.
The algorithm to resize the array is not trivial because of the possibility of the start and end indices wrapping around back to the start of the array. You can't just expand the array and add new elements to the end, because they might cut in front of older ones.
Instead, you can "unwrap" the queue by copying the start element (wherever it is) into the 0 slot of the new array, and follow it with all the other elements. The following algorithm expresses this idea:
enqueuemethod to check if the array is full before doing anything else. If so, call a
When your additions are done, the program should produce the following output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Exception thrown correctly!
If you are getting the wrong numbers or numbers out of order, it means you mixed up the algorithm a little bit.
When you're finished, please submit your code for this lab on Canvas.
Copyright © 2021 Ian Finlayson | Licensed under a Creative Commons Attribution 4.0 International License.