com.marringtons.util
Class Stack

java.lang.Object
  extended bycom.marringtons.util.Stack

public class Stack
extends Object

A stack is a simple array where data is always pushed to and popped off the end.

 stack = new Stack();
 stack.push( "one");
 stack.isEmpty() == false;
 stack.size() == 1;
 stack.push( "two");
 ((String) stack.peek()).equals( "two");
 ((String) stack.pop()).equals( "two");
 ((String) stack.peek()).equals( "one");
 stack.clear();
 stack.isEmpty() == true;
 

Author:
Paul Marrington

Constructor Summary
Stack()
           
 
Method Summary
 void clear()
          Empty stack - releasing all references.
 boolean isEmpty()
          Return true only if the stack is devoid of items.
 Object peek()
          Return the object on the top of the stack (without changint the stack pointer).
 Object pop()
          Pop an object from the stack.
 void push(Object item)
          Push an object onto the stack (enlarging it if necessary).
 int size()
          Return the number of items currently on the stack.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Stack

public Stack()
Method Detail

push

public void push(Object item)
Push an object onto the stack (enlarging it if necessary).

Parameters:
item - to push

pop

public Object pop()
Pop an object from the stack.

Returns:
most recently added item or null if stack is empty

peek

public Object peek()
Return the object on the top of the stack (without changint the stack pointer).

Returns:
most recently added item or null if stack is empty

size

public int size()
Return the number of items currently on the stack.

Returns:
the number if items on the stack.

isEmpty

public boolean isEmpty()
Return true only if the stack is devoid of items.

Returns:
true if the stack is empty.

clear

public void clear()
Empty stack - releasing all references.



Copyright © 2005 Paul Marrington http://library.marringtons.com