structure
Class StackVector

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

public class StackVector
extends AbstractStack
implements Stack

An implementation of stacks using Vectors.


Constructor Summary
StackVector()
          Construct an empty stack.
StackVector(int size)
          Construct a stack with initial capacity Vector will grow if the stack fills vector.
 
Method Summary
 void add(Object item)
          Add an element from the top of the stack.
 void clear()
          Remove all elements from stack.
 Object get()
          Fetch a reference to the top element of the stack.
 boolean isEmpty()
          Returns true iff the stack is empty.
 Iterator iterator()
          Returns an iterator for traversing the structure.
 Object remove()
          Remove an element from the top of the stack.
 int size()
          Determine the number of elements in stack.
 String toString()
          Construct a string representation of 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

StackVector

public StackVector()
Construct an empty stack.


StackVector

public StackVector(int size)
Construct a stack with initial capacity Vector will grow if the stack fills vector.

Parameters:
size - The initial capacity of the vector.
Method Detail

add

public void add(Object item)
Add an element from 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 element to be added to the stack top.
See Also:
Stack.push(java.lang.Object)

remove

public Object remove()
Remove an element from the top of the stack.

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

get

public Object get()
Fetch a reference to the top element of the stack.

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

isEmpty

public boolean isEmpty()
Returns true iff the stack is empty. Provided for compatibility with java.util.Vector.empty.

Specified by:
isEmpty in interface Structure
Overrides:
isEmpty in class AbstractStructure
Returns:
True iff the stack is empty.

size

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

Specified by:
size in interface Linear
Specified by:
size in interface Stack
Specified by:
size in interface Structure
Returns:
The number of elements in stack.

clear

public void clear()
Remove all elements from stack.

Specified by:
clear in interface Structure

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()

toString

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

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