|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectstructure.AbstractStructure<ELTTYPE>
structure.AbstractLinear<ELTTYPE>
structure.AbstractStack<ELTTYPE>
structure.StackVector<ELTTYPE>
public class StackVector<ELTTYPE>
An implementation of a stack, based on extensible arrays. The head of the stack is stored in the first position of the list, allowing the stack to grow and shrink in constant time. This stack implementation is ideal for applications that require a dynamically resizable stack which occasionally takes a time proportional to the its length to expand.
Example usage:
To reverse a string with a stack array, we would use the following:
public static void main(String[] arguments)
{
if(arguments.length > 0){
StackVector reverseStack = new StackVector();
String s = arguments[0];
for(int i=0; i < s.length(); i++){
reverseStack.push(new Character(s.charAt(i)));
}
while(!reverseStack.AbstractLinear.empty()){
System.out.print(reverseStack.AbstractStack.pop());
}
System.out.println();
}
}
Stack,
StackList,
StackArray,
AbstractStack| 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(ELTTYPE item)
Add an element from the top of the stack. |
void |
clear()
Remove all elements from stack. |
ELTTYPE |
get()
Fetch a reference to the top element of the stack. |
boolean |
isEmpty()
Returns true iff the stack is empty. |
java.util.Iterator<ELTTYPE> |
iterator()
Returns an iterator for traversing the structure. |
ELTTYPE |
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 |
|---|
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 |
|---|
public StackVector()
public StackVector(int size)
size - The initial capacity of the vector.| Method Detail |
|---|
public void add(ELTTYPE item)
add in interface Linear<ELTTYPE>add in interface Stack<ELTTYPE>add in interface Structure<ELTTYPE>item - The element to be added to the stack top.Stack.push(ELTTYPE)public ELTTYPE remove()
remove in interface Linear<ELTTYPE>remove in interface Stack<ELTTYPE>AbstractStack.pop()public ELTTYPE get()
get in interface Linear<ELTTYPE>get in interface Stack<ELTTYPE>public boolean isEmpty()
isEmpty in interface Structure<ELTTYPE>isEmpty in class AbstractStructure<ELTTYPE>public int size()
size in interface Linear<ELTTYPE>size in interface Stack<ELTTYPE>size in interface Structure<ELTTYPE>public void clear()
clear in interface Structure<ELTTYPE>public java.util.Iterator<ELTTYPE> iterator()
Structure
iterator in interface java.lang.Iterable<ELTTYPE>iterator in interface Structure<ELTTYPE>AbstractIterator,
Iterator,
Enumeration,
Structure.elements()public java.lang.String toString()
toString in class java.lang.Object
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||