Class Stack2

java.lang.Object
  extended by Stack2

public class Stack2
extends java.lang.Object

Implementation of a stack as an array

Author:
Mark Guzdial, Barb Ericson

Constructor Summary
Stack2()
          No argument constructor
 
Method Summary
 boolean empty()
          Method to check if the stack is empty
static void main(java.lang.String[] args)
           
 java.lang.Object peek()
          Method to return the top element on the stack but not remove it.
 java.lang.Object pop()
          Method to remove and return the top element on the stack
 void push(java.lang.Object 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

Stack2

public Stack2()
No argument constructor

Method Detail

push

public void push(java.lang.Object element)
Method to add an element to the top of the stack

Parameters:
element - the element to add

peek

public java.lang.Object peek()
Method to return the top element on the stack but not remove it.

Returns:
the object at the top of the stack

pop

public java.lang.Object pop()
Method to remove and return the top element on the stack

Returns:
the element on the top of the stack

size

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

Returns:
the number of elements in the stack

empty

public boolean empty()
Method to check if the stack is empty

Returns:
true if the stack is empty else false

main

public static void main(java.lang.String[] args)