Class LStack

java.lang.Object
  |
  +--LStack

public class LStack
extends Object

LStack.java
Illustrates the implementation of a stack based on a linked list.

Created: Mon Mar 24 10:37:56 2003

Author:
Stuart C. Shapiro

Constructor Summary
LStack()
          Creates a new LStack instance.
 
Method Summary
 boolean empty()
          Determines if this LStack is empty.
 Object pop()
          Removes and returns the Object on the top of this LStack.
 void push(Object obj)
          Adds a new Object to the top of this LStack.
 Object top()
          Returns the Object on the top of this LStack.
 String toString()
          Returns a String representation of this LStack, with the top Object shown at the left.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LStack

public LStack()
Creates a new LStack instance.

Method Detail

empty

public boolean empty()
Determines if this LStack is empty.

Returns:
true if this LStack has no elements in it; otherwise returns false.

push

public void push(Object obj)
Adds a new Object to the top of this LStack.

Parameters:
obj - the Object to be pushed onto this LStack.

top

public Object top()
           throws NoSuchElementException
Returns the Object on the top of this LStack.

Returns:
the Object on the top of this LStack.
Throws:
NoSuchElementException - if this LStack is empty.

pop

public Object pop()
           throws NoSuchElementException
Removes and returns the Object on the top of this LStack.

Returns:
the Object that was on the top of this LStack, after removing it.
Throws:
NoSuchElementException - if this LStack is empty.

toString

public String toString()
Returns a String representation of this LStack, with the top Object shown at the left.

Overrides:
toString in class Object
Returns:
a String representation of this LStack.