edu.trinity.cs.bmassing.adt1
Class FixedArrayStack<E>

java.lang.Object
  extended by edu.trinity.cs.bmassing.adt1.FixedArrayStack<E>
All Implemented Interfaces:
SimpleStack<E>

public class FixedArrayStack<E>
extends java.lang.Object
implements SimpleStack<E>

Class for fixed-size array-based stacks.


Constructor Summary
FixedArrayStack(int size)
          Constructs a new FixedArrayStack of the specified size.
 
Method Summary
 boolean empty()
          Tells whether stack is empty.
static void main(java.lang.String[] args)
          Performs minimal testing/demo of other functions.
 E pop()
          Pops an element from the stack.
 void push(E x)
          Pushes an element onto the stack.
 E top()
          Gets the top element of the stack (but does not remove it).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FixedArrayStack

public FixedArrayStack(int size)
Constructs a new FixedArrayStack of the specified size.

Parameters:
size - maximum number of elements
Method Detail

empty

public boolean empty()
Tells whether stack is empty.

Specified by:
empty in interface SimpleStack<E>
Returns:
true if stack is empty, false otherwise

push

public void push(E x)
          throws StackFullException
Pushes an element onto the stack.

Specified by:
push in interface SimpleStack<E>
Parameters:
x - element to add
Throws:
StackFullException - if stack is already full

pop

public E pop()
      throws StackEmptyException
Pops an element from the stack.

Specified by:
pop in interface SimpleStack<E>
Returns:
(former) top element of stack
Throws:
StackEmptyException - if stack is empty

top

public E top()
      throws StackEmptyException
Gets the top element of the stack (but does not remove it).

Specified by:
top in interface SimpleStack<E>
Returns:
top element of stack
Throws:
StackEmptyException - if stack is empty

main

public static void main(java.lang.String[] args)
Performs minimal testing/demo of other functions.

Parameters:
args - command-line arguments (unused)