//--------------------------------------------------------------------------- // ArrayUnbndQueueFloat.java by Dale/Joyce/Weems Chapter 5 // // Implements UnboundedQueueInterface with an array to hold queue elements. // // Two constructors are provided; one that creates a queue of a default // original capacity and one that allows the calling program to specify the // original capacity. // // If an enqueue is attempted when there is no room available in the array, a // new array is created, with capacity incremented by the original capacity. // // AJG version: MAJOR change *not* generic (since java can't do generic arrays) // Should be able to change ALL Float's to any other type // Format, enlarge() DOUBLES capacity, if-then-else //--------------------------------------------------------------------------- package ch05.queues; public class ArrayUnbndQueueFloat implements UnboundedQueueInterfaceFloat { private static final int DEFCAP = 100; // default capacity private Float[] array; // array that holds queue elements private int numElements = 0; // number of elements in the queue private int front = 0; // index of front of queue private int rear; // index of rear of queue public ArrayUnbndQueueFloat(int capacity) { array = new Float[capacity]; rear = capacity - 1; } public ArrayUnbndQueueFloat() { this(DEFCAP); } // Double the capacity of the queue private void enlarge() { // create the larger array Float[] larger = new Float[2*array.length]; // copy the array; shifting contents so that front is zero for (int i=0; i