Class LinkedListStack<E>

java.lang.Object
  extended by LinkedListStack<E>
All Implemented Interfaces:
Stack<E>

public class LinkedListStack<E>
extends Object
implements Stack<E>

Class that represents a stack using a linked list of objects

Author:
Mark Guzdial, Barb Ericson

Constructor Summary
LinkedListStack()
          Constructor that takes no arguments
 
Method Summary
 boolean isEmpty()
          Method to test if the stack is empty
 E peek()
          Method to return the top element on the stack but leave the element on the stack
 E pop()
          Method to remove the top element from a stack and return it
 void push(E element)
          Method to add an element to the stack
 int size()
          Method to get the number of elements in the stack
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LinkedListStack

public LinkedListStack()
Constructor that takes no arguments

Method Detail

push

public void push(E element)
Method to add an element to the stack

Specified by:
push in interface Stack<E>
Parameters:
element - the element to add

peek

public E peek()
Method to return the top element on the stack but leave the element on the stack

Specified by:
peek in interface Stack<E>
Returns:
the top element on the stack

pop

public E pop()
Method to remove the top element from a stack and return it

Specified by:
pop in interface Stack<E>
Returns:
the top element from the stack and remove it

size

public int size()
Method to get the number of elements in the stack

Specified by:
size in interface Stack<E>
Returns:
the number of elements in the stack

isEmpty

public boolean isEmpty()
Method to test if the stack is empty

Specified by:
isEmpty in interface Stack<E>
Returns:
true if the stack is empty, else false