uk.org.redfelineninja.util
Class IntStack

java.lang.Object
  |
  +--uk.org.redfelineninja.util.IntStack

public class IntStack
extends java.lang.Object

This stack class represents a last-in-first-out (LIFO) stack of integers. In some cases speed is of paramount importance, in such cases java.util.Stack should be avoided since its use forces object creation. Object creation is time consuming.

The method names used in this class are taken from java.util.Vector and java.util.Stack so there should be little memory burdon in using this class.

Author:
Daniel Thompson (Feb 1999)

Constructor Summary
IntStack()
          Creates an empty stack with the default initial size.
IntStack(int size)
          Creates an empty stack with specified initial size.
 
Method Summary
 boolean empty()
          Test whether or not the stack is empty.
 int peek()
          Peek at the top of the stack.
 int pop()
          Pop an item off the stack.
 void push(int item)
          Push an item onto the stack.
 int size()
          Get the size of the stack.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IntStack

public IntStack()
Creates an empty stack with the default initial size.


IntStack

public IntStack(int size)
Creates an empty stack with specified initial size.

Parameters:
size - initial size and capacity increment
Method Detail

push

public final void push(int item)
Push an item onto the stack.

Parameters:
item - the item to be pushed

pop

public final int pop()
Pop an item off the stack.

Returns:
the item removed

peek

public final int peek()
Peek at the top of the stack.

Returns:
the value at the top of the stack

empty

public final boolean empty()
Test whether or not the stack is empty.

Returns:
true if the stack is empty

size

public final int size()
Get the size of the stack.

Returns:
size