net.datastructures - version 3.0

net.datastructures
Interface Deque

All Known Implementing Classes:
NodeDeque

public interface Deque

Interface for a deque (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:
EmptyDequeException, Queue, Stack

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

Method Detail

first

public Object first()
             throws EmptyDequeException
Gets the first element (without modifying the deque).

Returns:
first element in the deque.
Throws:
EmptyDequeException - if the deque is empty

last

public Object last()
            throws EmptyDequeException
Gets the last element (without modifying the deque).

Returns:
last element in the deque.
Throws:
EmptyDequeException - 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(Object element)
Insert an element at the beginning.

Parameters:
element - new element to be inserted.

insertLast

public void insertLast(Object element)
Insert an element at the end.

Parameters:
element - new element to be inserted.

removeFirst

public Object removeFirst()
                   throws EmptyDequeException
Remove the element at the beginning.

Returns:
element removed.
Throws:
EmptyDequeException - if the deque is empty

removeLast

public Object removeLast()
                  throws EmptyDequeException
Remove the element at the end.

Returns:
element removed.
Throws:
EmptyDequeException - if the deque is empty

net.datastructures - version 3.0