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.
add(Object)
- Add an element from the top of the stack.
empty()
- Returns true iff the stack is empty.
peek()
- Fetch a reference to the top element of the stack.
pop()
- Remove an element from the top of the stack.
push(Object)
- Add an element to top of stack.
remove()
- Remove an element from the top of the stack.
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
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.
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
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.
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.
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