All Packages  Class Hierarchy  This Package  Previous  Next  Index  

Interface structure.Stack

public interface Stack
extends Linear
An interface describing a Last-In, First-Out structure. Stacks are typically used to store the state of a recursively solved problem.


Method Index

 o add(Object)
Add an element from the top of the stack.
 o empty()
Returns true iff the stack is empty.
 o peek()
Fetch a reference to the top element of the stack.
 o pop()
Remove an element from the top of the stack.
 o push(Object)
Add an element to top of stack.
 o remove()
Remove an element from the top of the stack.

Methods

 o add
public abstract void add(Object item)
Add an element from the top of the stack.

Postcondition:
item is added to stack will be popped next if no intervening add

Parameters:
item - The element to be added to the stack top.
See Also:
push
 o push
public abstract void push(Object item)
Add an element to top of stack.

Postcondition:
item is added to stack will be popped next if no intervening push

Parameters:
item - The value to be added to the top of the stack.
 o remove
public abstract Object remove()
Remove an element from the top of the stack.

Precondition:
stack is not empty
Postcondition:
most recently added item is removed and returned

Returns:
The item removed from the top of the stack.
See Also:
pop
 o pop
public abstract Object pop()
Remove an element from the top of the stack.

Precondition:
stack is not empty
Postcondition:
most recently pushed item is removed and returned

Returns:
A reference to the removed element.
 o peek
public abstract Object peek()
Fetch a reference to the top element of the stack.

Precondition:
stack is not empty
Postcondition:
top value (next to be popped) is returned

Returns:
A reference to the top element of the stack.
 o empty
public abstract boolean empty()
Returns true iff the stack is empty. Provided for compatibility with java.util.Vector.empty.

Postcondition:
returns true if and only if the stack is empty

Returns:
True iff the stack is empty.
See Also:
isEmpty

All Packages  Class Hierarchy  This Package  Previous  Next  Index