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.


Field Summary
protected  Vector data
          The vector containing the stack data.
 
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(java.lang.Object item)
          Add an element from the top of the stack.
 void clear()
          Remove all elements from stack.
 java.lang.Object get()
          Fetch a reference to the top element of the stack.
 boolean isEmpty()
          Returns true iff the stack is empty.
 java.util.Iterator iterator()
          Returns an iterator for traversing the structure.
 java.lang.Object remove()
          Remove an element from the top of the stack.
 int size()
          Determine the number of elements in stack.
 java.lang.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
clone, equals, finalize, 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
 

Field Detail

data

protected Vector data
The vector containing the stack data.

Constructor Detail

StackVector

public StackVector()
Construct an empty stack.

Postcondition:
an empty stack is created

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.
Postcondition:
an empty stack with initial capacity of size is created
Method Detail

add

public void add(java.lang.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)
Postcondition:
item is added to stack will be popped next if no intervening add

remove

public java.lang.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()
Precondition:
stack is not empty
Postcondition:
most recently added item is removed and returned

get

public java.lang.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.
Precondition:
stack is not empty
Postcondition:
top value (next to be popped) is returned

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.
Postcondition:
returns true if and only if 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.
Postcondition:
returns the number of elements in stack

clear

public void clear()
Remove all elements from stack.

Specified by:
clear in interface Structure
Postcondition:
removes all elements from stack

iterator

public java.util.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 java.lang.String toString()
Construct a string representation of stack.

Overrides:
toString in class java.lang.Object
Returns:
A string representing the stack.
Postcondition:
returns a string representation of stack