1: // @author Frank M. Carrano, Timothy M. Henry 2: // @version 5.0 3: public void push(T newEntry) 4: { 5: checkInyegrity(); 6: ensureCapacity(); 7: stack[topIndex + 1] = newEntry; 8: topIndex++; 9: } // end push 11: private void ensureCapacity() 12: { 13: if (topIndex >= stack.length - 1) // If array is full, double its size 14: { 15: int newLength = 2 * stack.length; 16: checkCapacity(newLength); 17: stack = Arrays.copyOf(stack, newLength); 18: } // end if 19: } // end ensureCapacity