jdsl.simple.api
Interface Deque

All Known Implementing Classes:
MyDeque, NodeRankedSequence

public abstract interface Deque

Interface for a deque, or double-ended queue.

A deque is a collection of linearly arranged elements that are accessed, inserted, and removed at the beginning or at the end.

Author:
Michael T. Goodrich, Mark Handy, Roberto Tamassia
See Also:
DequeEmptyException, Queue, Stack

Method Summary
 java.lang.Object first()
          Gets the first element (without modifying the deque).
 void insertFirst(java.lang.Object element)
          Insert an element at the beginning.
 void insertLast(java.lang.Object element)
          Insert an element at the end.
 boolean isEmpty()
          Tests if this deque is empty
 java.lang.Object last()
          Gets the last element (without modifying the deque).
 java.lang.Object removeFirst()
          Remove the element at the beginning.
 java.lang.Object removeLast()
          Remove the element at the end.
 int size()
          Gets the number of elements.
 

Method Detail

first

public java.lang.Object first()
                       throws DequeEmptyException
Gets the first element (without modifying the deque).
Returns:
first element in the deque.
Throws:
DequeEmptyException - if the deque is empty

last

public java.lang.Object last()
                      throws DequeEmptyException
Gets the last element (without modifying the deque).
Returns:
last element in the deque.
Throws:
DequeEmptyException - if the deque is empty

isEmpty

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

size

public int size()
Gets the number of elements.
Returns:
number of elements in the deque.

insertFirst

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

insertLast

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

removeFirst

public java.lang.Object removeFirst()
                             throws DequeEmptyException
Remove the element at the beginning.
Returns:
element removed.
Throws:
DequeEmptyException - if the deque is empty

removeLast

public java.lang.Object removeLast()
                            throws DequeEmptyException
Remove the element at the end.
Returns:
element removed.
Throws:
DequeEmptyException - if the deque is empty