The goal of this lab period is to give you an opportunity to implement a stack.
Implement an IntStack class, which usses an array of ints to store the elements. It should have a field (of type int) to keep track of the index of the top of the stack and a field to store the elements (int). It should implement the following methods:
public IntStack( )- constructor method. Make an array of 10 ints and initialize the top index to be 0.
public void push( int new_item ). Push a new item onto the stack. If there isn't enough room in the array, then make a new array and copy the data over.
public int pop(). Pop and item off the stack and return it.
public int elementAt( int index ). Return the element at the given position (do not modify the stack).
public int size(). Return the number of items in the stack.
public boolean isEmpty(). Returns true if the stack is empty.
- Write a main method testing every method in your class. The test it and debug it until it is perfect. :)
One of your tests should be to push 20 items onto your stack.
Once you have completed the lab and feel comfortable with stacks, go on to the project.