Class ArrayStack<E>

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

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

Implementation of a stack as an array

Author:
Mark Guzdial, Barb Ericson

Constructor Summary
ArrayStack()
          No argument constructor
 
Method Summary
 boolean isEmpty()
          Method to check if the stack is empty
static void main(String[] args)
           
 E peek()
          Method to return the top element on the stack but not remove it.
 E pop()
          Method to remove and return the top element on the stack
 void push(E element)
          Method to add an element to the top of the stack
 int size()
          Method to return 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

ArrayStack

public ArrayStack()
No argument constructor

Method Detail

push

public void push(E element)
Method to add an element to the top of 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 not remove it.

Specified by:
peek in interface Stack<E>
Returns:
the object at the top of the stack

pop

public E pop()
Method to remove and return the top element on the stack

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

size

public int size()
Method to return 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 check if the stack is empty

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

main

public static void main(String[] args)