|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Stack<ELTTYPE>
An interface describing a Last-In, First-Out structure. Stacks are typically used to store the state of a recursively solved problem. The structure package provides several implementations of the Stack interface, 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){Stack
reverseStack = newStackList()
; String s = arguments[0]; for(int i=0; i < s.length(); i++){ reverseStack.push(new Character(s.charAt(i)))
; } while(!reverseStack.empty()
){ System.out.print(reverseStack.pop()
); } System.out.println(); } }
Method Summary | |
---|---|
void |
add(ELTTYPE item)
Add an element from the top of the stack. |
boolean |
empty()
Returns true iff the stack is empty. |
ELTTYPE |
get()
Fetch a reference to the top element of the stack. |
ELTTYPE |
getFirst()
Fetch a reference to the top element of the stack. |
ELTTYPE |
peek()
Fetch a reference to the top element of the stack. |
ELTTYPE |
pop()
Remove an element from the top of the stack. |
void |
push(ELTTYPE item)
Add an element to top of stack. |
ELTTYPE |
remove()
Remove an element from the top of the stack. |
int |
size()
Returns the number of elements in the stack. |
Methods inherited from interface structure.Structure |
---|
clear, contains, elements, isEmpty, iterator, remove, values |
Method Detail |
---|
void add(ELTTYPE item)
add
in interface Linear<ELTTYPE>
add
in interface Structure<ELTTYPE>
item
- The element to be added to the stack top.push(ELTTYPE)
void push(ELTTYPE item)
item
- The value to be added to the top of the stack.ELTTYPE remove()
remove
in interface Linear<ELTTYPE>
pop()
ELTTYPE pop()
ELTTYPE get()
get
in interface Linear<ELTTYPE>
ELTTYPE getFirst()
ELTTYPE peek()
boolean empty()
empty
in interface Linear<ELTTYPE>
int size()
size
in interface Linear<ELTTYPE>
size
in interface Structure<ELTTYPE>
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |