structure
Class StackArray

java.lang.Object
  extended by structure.AbstractStructure
      extended by structure.AbstractLinear
          extended by structure.AbstractStack
              extended by structure.StackArray
All Implemented Interfaces:
Linear, Stack, Structure

public class StackArray
extends AbstractStack
implements Stack

An implementation of a stack using an array.


Constructor Summary
StackArray(int size)
          Construct a stack capable of holding at least size elements.
 
Method Summary
 void add(Object item)
          Add a value to the top of the stack.
 void clear()
          Remove all elements from the stack.
 Object get()
          Get a reference to the top value in the stack.
 boolean isEmpty()
          Determine if the stack is empty.
 boolean isFull()
          Determine if the stack is full.
 Iterator iterator()
          Returns an iterator for traversing the structure.
 Object remove()
          Remove a value from the top of the stack.
 int size()
          Determine the number of elements in the stack.
 String toString()
          Construct a string representation of the stack.
 
Methods inherited from class structure.AbstractStack
getFirst, peek, pop, push
 
Methods inherited from class structure.AbstractLinear
empty, remove
 
Methods inherited from class structure.AbstractStructure
contains, elements, hashCode, values
 
Methods inherited from class java.lang.Object
equals, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface structure.Stack
empty, getFirst, peek, pop, push
 
Methods inherited from interface structure.Structure
contains, elements, remove, values
 

Constructor Detail

StackArray

public StackArray(int size)
Construct a stack capable of holding at least size elements.

Parameters:
size - The maximum size of the stack.
Method Detail

clear

public void clear()
Remove all elements from the stack.

Specified by:
clear in interface Structure

add

public void add(Object item)
Add a value to the top of the stack.

Specified by:
add in interface Linear
Specified by:
add in interface Stack
Specified by:
add in interface Structure
Parameters:
item - The value to be added.
See Also:
AbstractStack.push(java.lang.Object)

remove

public Object remove()
Remove a value from the top of the stack.

Specified by:
remove in interface Linear
Specified by:
remove in interface Stack
Returns:
The value removed from the top of the stack.
See Also:
AbstractStack.pop()

get

public Object get()
Get a reference to the top value in the stack.

Specified by:
get in interface Linear
Specified by:
get in interface Stack
Returns:
A reference to the top element of the top of the stack.

iterator

public Iterator iterator()
Description copied from interface: Structure
Returns an iterator for traversing the structure.

Specified by:
iterator in interface Structure
Returns:
an iterator for traversing the structure
See Also:
AbstractIterator, Iterator, Enumeration, Structure.elements()

size

public int size()
Determine the number of elements in the stack.

Specified by:
size in interface Linear
Specified by:
size in interface Stack
Specified by:
size in interface Structure
Returns:
The number of values within the stack.

isEmpty

public boolean isEmpty()
Determine if the stack is empty.

Specified by:
isEmpty in interface Structure
Overrides:
isEmpty in class AbstractStructure
Returns:
True iff the stack is empty.
See Also:
AbstractLinear.empty()

isFull

public boolean isFull()
Determine if the stack is full.

Returns:
True iff there is no more room in the stack.

toString

public String toString()
Construct a string representation of the stack.

Overrides:
toString in class Object
Returns:
A string representing the stack.