jdsl.simple.ref
Class MyDeque

java.lang.Object
  |
  +--jdsl.simple.ref.MyDeque
Direct Known Subclasses:
NodeRankedSequence

public class MyDeque
extends java.lang.Object
implements Deque

This is the implementation of the Deque interface Dbmy means of a doubly- linked list. Note that this class uses class DLNode, which is the node that stores the previos and next nodes in the list, and a reference to its element.

Author:
Natasha Gelfand

Constructor Summary
MyDeque()
           
 
Method Summary
 java.lang.Object first()
          Inspect the first element without modifying the deque.
 void insertFirst(java.lang.Object o)
          Add an element at the front of the sequence.
 void insertLast(java.lang.Object o)
          Add an element at the back of the sequence.
 boolean isEmpty()
          This function returns true if and only if the deque is empty
 java.lang.Object last()
          Inspect the last element without modifying the deque.
 java.lang.Object removeFirst()
          Delete the element at the front of the sequence.
 java.lang.Object removeLast()
          Delete the element at the back of the sequence.
 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

MyDeque

public MyDeque()
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
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
Returns:
true if the deque is empty, false otherwise

first

public java.lang.Object first()
                       throws DequeEmptyException
Inspect the first element without modifying the deque.
Specified by:
first in interface Deque
Returns:
The first element in the sequence

last

public java.lang.Object last()
                      throws DequeEmptyException
Inspect the last element without modifying the deque.
Specified by:
last in interface Deque
Returns:
The last element in the sequence

insertFirst

public void insertFirst(java.lang.Object o)
Add an element at the front of the sequence.
Specified by:
insertFirst in interface Deque
Parameters:
element - New element for the front of the deque

insertLast

public void insertLast(java.lang.Object o)
Add an element at the back of the sequence.
Specified by:
insertLast in interface Deque
Parameters:
element - New element for the back of the deque

removeFirst

public java.lang.Object removeFirst()
                             throws DequeEmptyException
Delete the element at the front of the sequence.
Specified by:
removeFirst in interface Deque
Returns:
The element formerly known as "first()"

removeLast

public java.lang.Object removeLast()
                            throws DequeEmptyException
Delete the element at the back of the sequence.
Specified by:
removeLast in interface Deque
Returns:
The element formerly known as "last()"