m865.datastructures
Class StackLL

java.lang.Object
  extended bym865.datastructures.AbstractStack
      extended bym865.datastructures.StackLL
All Implemented Interfaces:
java.lang.Cloneable, java.util.Collection

public class StackLL
extends AbstractStack

This class implements a Stack using a simple Linked List.

Version:
2.1 09/11/05
Author:
Daniel D. Warner

Nested Class Summary
protected  class StackLL.Link
          The Linked List is built from a simple forward link.
 class StackLL.StackLLIterator
          An iterator for an ArrayList stack.
 
Field Summary
protected  StackLL.Link top
          The Linked List starts with this link.
 
Fields inherited from class m865.datastructures.AbstractStack
hash
 
Constructor Summary
  StackLL()
          Constructs a stack which uses a simple Linked List.
  StackLL(java.util.Collection c)
          Constructs a stack which is initialized with the objects in the specified collection
protected StackLL(int hash, StackLL.Link topOfLinkedList)
          Constructs a stack with a specified hash code and a specified linked list.
 
Method Summary
 void clear()
          Removes all the objects from this stack.
 java.lang.Object clone()
          The Cloneable Interface indicates that the clone method, which is inherited from Object, is implemented so that a true clone (a true and independent copy) of the object is returned.
 boolean isEmpty()
          Determines whether the stack is empty.
 java.util.Iterator iterator()
          A factory method which returns an Iterator to the collection in this stack.
static void main(java.lang.String[] args)
          This main method tests the StackLL class to insure that the elementary functions are correct.
 java.lang.Object peek()
          Returns the object on the top of the stack.
 java.lang.Object pop()
          Removes and returns the object on the top of the stack.
 void push(java.lang.Object obj)
          Pushes an object onto the top of the stack.
 int size()
          Determines the size of this stack.
 java.lang.String toString()
          List the objects in the stack
 
Methods inherited from class m865.datastructures.AbstractStack
add, addAll, contains, containsAll, downdateHashCode, equals, hashCode, remove, removeAll, retainAll, toArray, toArray, updateHashCode
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

top

protected StackLL.Link top
The Linked List starts with this link.

Constructor Detail

StackLL

public StackLL()
Constructs a stack which uses a simple Linked List.


StackLL

public StackLL(java.util.Collection c)
Constructs a stack which is initialized with the objects in the specified collection

Parameters:
c - the collection of objects to be initially pushed onto this stack.

StackLL

protected StackLL(int hash,
                  StackLL.Link topOfLinkedList)
Constructs a stack with a specified hash code and a specified linked list. This constuctor is only for use within the class and its subclasses.

Parameters:
hash - the hash code
topOfLinkedList - the top of the linked list.
Method Detail

push

public void push(java.lang.Object obj)
Pushes an object onto the top of the stack.

Specified by:
push in class AbstractStack
Parameters:
obj - the object to be placed on the top of the stack.

pop

public java.lang.Object pop()
Removes and returns the object on the top of the stack.

Specified by:
pop in class AbstractStack
Returns:
the object on the top of the stack or null if the stack is empty.

peek

public java.lang.Object peek()
Returns the object on the top of the stack. The stack remains unchanged.

Specified by:
peek in class AbstractStack
Returns:
the object on the top of the stack or null if the stack is empty.

clear

public void clear()
Removes all the objects from this stack. This is one of the optional operations specified by the Collection Interface


clone

public java.lang.Object clone()
The Cloneable Interface indicates that the clone method, which is inherited from Object, is implemented so that a true clone (a true and independent copy) of the object is returned.

Returns:
a clone (a true and independent copy) of this stack.

isEmpty

public boolean isEmpty()
Determines whether the stack is empty.

Specified by:
isEmpty in interface java.util.Collection
Overrides:
isEmpty in class AbstractStack
Returns:
true - if this collection contains no elements.

iterator

public java.util.Iterator iterator()
A factory method which returns an Iterator to the collection in this stack. This iterator will walk throught the stack from the top to the bottom. It will throw a ConcurrentModificationException if the stack is altered during the iteration.

Returns:
a StackAL iterator.

size

public int size()
Determines the size of this stack.

Returns:
the number of objects in this stack.

toString

public java.lang.String toString()
List the objects in the stack

Overrides:
toString in class AbstractStack
Returns:
a formatted string listing the objects in this stack

main

public static void main(java.lang.String[] args)
This main method tests the StackLL class to insure that the elementary functions are correct.

Parameters:
args - optional command line arguments which will be ignored.