14.7 Array Representation of Queues
Earlier in this chapter, we also saw how a queue can be represented by a linked list. Again, if we know in advance that the number of objects in a queue will always be less than some maximum number, we can also use an array to represent the queue.
To match the FIFO functionality of a queue, we will need to keep track of two things:
the location of the back of the queue. This is the index of the last element enqueued or added to the queue. We will call the index of that element back.
the location of the front of the queue. That is the index of the element that will be dequeued or retrieved next. We will call the index of that element front.
The queue will be comprised of the elements whose indexes are between ...
Get Java Illuminated, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.