![]() ![]() A set of private const ints with a meaningful name would help. If you wish to change this in the future you would have to look deep through the code (if it extends) to change it. This is effectively the loadfactor for your resizing. In the intrest of making it more readable, I would recommend removing magic numbers which are critical to your implementation. ![]() I didn't test this implementation but it should work well. System.arraycopy(queue, 0, copy, queue.length - head, tail) System.arraycopy(queue, head, copy, 0, queue.length - head) System.arraycopy(queue, head, copy, 0, size) Your code looks good, but can be improved. * Resizes the array when capacity reaches 100% or 25% Throw new NoSuchElementException("There is nothing in the queue") * NoSuchElementException if dequeue() is called while the queue is * the queue reaches 25% of the length of the array, the length of the array * Removes and returns the item at the front of the queue. Throw new NullPointerException("Item must not be null") * NullPointerException if the parameter item is null * the length of the array, the length of the array is doubled. * Adds an item onto the end of the queue. * Returns whether or not the queue is empty * Integer representing the number of items in the queue * ResizingQueue - Resizing Array Implementation. After learning about linked list implementations of a queue I was asked to try a resizing array implementation. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |