I would like to use an array to implement an IntegerQueue class to store a queue of integers. I believe this class should have the same methods as the IntegerStack class which I have created below except that the push and pop methods should be renamed addToQueue and removeFromQueue respectively.
Here is what I have so far but it is more of a stack then a queue currently:
public class IntegerQueue { private int [] queue; private int total; // to track number of items
public IntegerQueue (int sizeIn) { // size array with parameter stack = new int [sizeIn]; // set number of items to zero total = 0; }
// add an item to the array public boolean addToQueue (int j) { if( isFull() == false) // checks if space is stock { stack[total] = j; // add item total++; // increment item counter return true; //to indicate success } else { return false; // to indicate failure } }
// remove an item by obeying LIFO rule public boolean removeFromQueue() { if( isEmpty() == false) // makes sure stack is not empty { total 0; return true; // to indicate success } else { return false; // to indicate failure } }
// checks if array is empty public boolean isEmpty() { if(total==0) { return true; } else { return false; } }
// checks if array is full public boolean isFull() { if (total==stack.length) { return true; } else { return false; } }
// returns the ith item public int getItem(int i) { return stack[i-1]; // ith item at position i-1 }
// return the number of items in the array public int getTotal() { return total; } }