com.sun.labs.minion.util
Class Stack

java.lang.Object
  extended by com.sun.labs.minion.util.Stack

public class Stack
extends java.lang.Object

A stack of Java objects.


Field Summary
protected  int N
          The number of elements in the stack.
protected  java.lang.Object[] stack
          An array to store the objects in.
 
Constructor Summary
Stack()
          Build a default-sized stack.
Stack(int n)
          Build a stack with a given number of elements available.
Stack(Stack s)
          Build a stack from another stack.
 
Method Summary
 boolean empty()
          Test whether this Stack is empty.
protected  void ensureCapacity(int n)
          Ensure that there is enough room in the stack for the given number of elements.
 java.lang.Object peek()
          Peek at the top of the stack, but don't return it.
 java.lang.Object pop()
          Pop the top element off the stack.
 void push(java.lang.Object o)
          Push an element onto the stack.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stack

protected java.lang.Object[] stack
An array to store the objects in.


N

protected int N
The number of elements in the stack.

Constructor Detail

Stack

public Stack()
Build a default-sized stack.


Stack

public Stack(int n)
Build a stack with a given number of elements available.


Stack

public Stack(Stack s)
Build a stack from another stack.

Method Detail

ensureCapacity

protected void ensureCapacity(int n)
Ensure that there is enough room in the stack for the given number of elements.

Parameters:
n - The number of elements we want to store.

empty

public boolean empty()
Test whether this Stack is empty.

Returns:
true if it is empty, false otherwise.

push

public void push(java.lang.Object o)
Push an element onto the stack.

Parameters:
o - the Object to push.

peek

public java.lang.Object peek()
Peek at the top of the stack, but don't return it.

Returns:
the object on top of the stack, or null if the stack is empty.

pop

public java.lang.Object pop()
Pop the top element off the stack.

Returns:
the object on top of the stack, or null if the stack is empty.