net.datastructures
Class NodeDeque<E>

java.lang.Object
  extended by net.datastructures.NodeDeque<E>
All Implemented Interfaces:
Deque<E>

public class NodeDeque<E>
extends java.lang.Object
implements Deque<E>

Implementation of the Deque interface by means of a doubly linked list. This class uses class DLNode, which implements a node of the list.

Author:
Natasha Gelfand, Roberto Tamassia

Constructor Summary
NodeDeque()
          Creates an empty deque.
 
Method Summary
 void addFirst(E o)
          Inserts an element to be the first in the deque.
 void addLast(E o)
          Inserts an element to be the last in the deque.
 E getFirst()
          Inspect the first element without modifying the deque.
 E getLast()
          Returns the last element; an exception is thrown if deque is empty.
 boolean isEmpty()
          This function returns true if and only if the deque is empty
 E removeFirst()
          Removes the first element; an exception is thrown if deque is empty.
 E removeLast()
          Removes the last element; an exception is thrown if deque is empty.
 int size()
          Return the size of the deque, that is the number of elements it has.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NodeDeque

public NodeDeque()
Creates an empty deque.

Method Detail

size

public int size()
Return the size of the deque, that is the number of elements it has.

Specified by:
size in interface Deque<E>
Returns:
Number of elements in the deque

isEmpty

public boolean isEmpty()
This function returns true if and only if the deque is empty

Specified by:
isEmpty in interface Deque<E>
Returns:
true if the deque is empty, false otherwise

getFirst

public E getFirst()
           throws EmptyDequeException
Inspect the first element without modifying the deque.

Specified by:
getFirst in interface Deque<E>
Returns:
The first element in the sequence
Throws:
EmptyDequeException

getLast

public E getLast()
          throws EmptyDequeException
Description copied from interface: Deque
Returns the last element; an exception is thrown if deque is empty.

Specified by:
getLast in interface Deque<E>
Throws:
EmptyDequeException

addFirst

public void addFirst(E o)
Description copied from interface: Deque
Inserts an element to be the first in the deque.

Specified by:
addFirst in interface Deque<E>

addLast

public void addLast(E o)
Description copied from interface: Deque
Inserts an element to be the last in the deque.

Specified by:
addLast in interface Deque<E>

removeFirst

public E removeFirst()
              throws EmptyDequeException
Description copied from interface: Deque
Removes the first element; an exception is thrown if deque is empty.

Specified by:
removeFirst in interface Deque<E>
Throws:
EmptyDequeException

removeLast

public E removeLast()
             throws EmptyDequeException
Description copied from interface: Deque
Removes the last element; an exception is thrown if deque is empty.

Specified by:
removeLast in interface Deque<E>
Throws:
EmptyDequeException