|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--structure.AbstractStructure | +--structure.AbstractLinear | +--structure.AbstractStack
An abstract structure implementing features common to all Last-In, First-Out structures in this package. Stacks are typically used to store the state of a recursively solved problem. The structure package provides several extensions of the AbstractStack class, each of which has its particular strengths and weaknesses.
Example usage:
To reverse a string using a stack, we would use the following:
public static void main(String[] arguments) { if(arguments.length > 0){AbstractStack
reverseStack = newStackList()
; 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.pop()
); } System.out.println(); } }
Stack
,
StackVector
,
StackList
,
StackArray
Constructor Summary | |
AbstractStack()
|
Method Summary | |
java.lang.Object |
getFirst()
Deprecated. Please use method get, rather than getFirst! |
java.lang.Object |
peek()
Fetch a reference to the top element of the stack. |
java.lang.Object |
pop()
Remove an element from the top of the stack. |
void |
push(java.lang.Object item)
Add an element from the top of the stack. |
Methods inherited from class structure.AbstractLinear |
empty, remove |
Methods inherited from class structure.AbstractStructure |
contains, elements, hashCode, isEmpty, values |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface structure.Stack |
add, empty, get, remove, size |
Methods inherited from interface structure.Structure |
clear, contains, elements, isEmpty, iterator, remove, values |
Constructor Detail |
public AbstractStack()
Method Detail |
public void push(java.lang.Object item)
push
in interface Stack
item
- The element to be added to the stack top.public java.lang.Object pop()
pop
in interface Stack
public java.lang.Object getFirst()
getFirst
in interface Stack
public java.lang.Object peek()
peek
in interface Stack
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |