Example #1
0
 public Item pop() throws EmptyStackException {
   if (size == 0) throw new EmptyStackException();
   size--;
   Item item = stack[size];
   stack[size] = null; // avoid loitering!
   if (size <= stack.length / 4) resize(stack.length / 2);
   return item;
 }
  public Item pop() {
    if (isEmpty()) throw new NoSuchElementException();

    Item item = a[--N];
    a[N] = null;

    if (N > 0 && N <= a.length / 4) resize(a.length / 2);

    return item;
  }
Example #3
0
 public void push(Item item) {
   if (size == stack.length) resize(2 * stack.length);
   stack[size] = item;
   size++;
 }
 public void push(Item item) {
   if (N >= a.length) resize(2 * a.length);
   a[N++] = item;
 }