jdsl.simple.api
Interface Stack

All Known Implementing Classes:
LinkedStack, DequeStack, ArrayStack, SequenceStack

public abstract interface Stack

Interface for a stack.

A stack is a collection of objects elements that are inserted and removed according to the last-in first-out principle.

Author:
Michael T. Goodrich, Mark Handy, Roberto Tamassia
See Also:
StackEmptyException, Queue, Deque

Method Summary
 boolean isEmpty()
          Tests if the stack is empty
 java.lang.Object pop()
          Remove the top element.
 void push(java.lang.Object element)
          Insert an element at the top.
 int size()
          Return the number of elements.
 java.lang.Object top()
          Inspect the top element, without removing it or otherwise modifying the stack.
 

Method Detail

size

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

isEmpty

public boolean isEmpty()
Tests if the stack is empty
Returns:
true if the stack is empty, false otherwise.

top

public java.lang.Object top()
                     throws StackEmptyException
Inspect the top element, without removing it or otherwise modifying the stack.
Returns:
top element in the stack.
Throws:
StackEmptyException - If this stack is empty.

push

public void push(java.lang.Object element)
Insert an element at the top.
Parameters:
element - new element to be inserted.

pop

public java.lang.Object pop()
                     throws StackEmptyException
Remove the top element.
Returns:
element removed.
Throws:
StackEmptyException - if this stack is empty