datastructures

net.datastructures
Interface Stack

All Known Implementing Classes:
ArrayStack, NodeStack

public interface Stack

Interface for a stack: a collection of objects that are inserted and removed according to the last-in first-out principle.

Author:
Roberto Tamassia, Michael Goodrich
See Also:
EmptyStackException

Method Summary
 boolean isEmpty()
          Return whether the stack is empty.
 Object pop()
          Remove the top element from the stack.
 void push(Object element)
          Insert an element at the top of the stack.
 int size()
          Return the number of elements in the stack.
 Object top()
          Inspect the element at the top of the stack.
 

Method Detail

size

public int size()
Return the number of elements in the stack.

Returns:
number of elements in the stack.

isEmpty

public boolean isEmpty()
Return whether the stack is empty.

Returns:
true if the stack is empty, false otherwise.

top

public Object top()
           throws EmptyStackException
Inspect the element at the top of the stack.

Returns:
top element in the stack.
Throws:
EmptyStackException - if the stack is empty.

push

public void push(Object element)
Insert an element at the top of the stack.

Parameters:
element - element to be inserted.

pop

public Object pop()
           throws EmptyStackException
Remove the top element from the stack.

Returns:
element removed.
Throws:
EmptyStackException - if the stack is empty.

datastructures