Class DoublyLinkedList

java.lang.Object
  extended by DoublyLinkedList

public class DoublyLinkedList
extends java.lang.Object

This class implements a doubly linked list of characters in Java. The instance variables head and tail are initially null. As elements are added head points to the first element on the list and tail points to the last element. Each node on the list is of type DoubleNode. Each DoubleNode holds a pointer to the previous node and a pointer to the next node in the list.


Constructor Summary
DoublyLinkedList()
          Constructs a new DoublyLinkedList object with head and tail as null.
 
Method Summary
 void addCharAtEnd(char c)
          Add a character node containing the character c to the end of the linked list.
 void addCharAtFront(char c)
          Add a character node containing the character c to the front of the linked list.
 int countNodes()
          Counts the number of nodes in the list.
 boolean deleteChar(char c)
          Deletes the first occurence of the character c from the list.
 boolean isEmpty()
          Returns true if the list is empty false otherwise
static void main(java.lang.String[] a)
           
 char removeCharAtEnd()
          Remove and return the character at the end of the doubly linked list.
 char removeCharFromFront()
          Remove and return the character at the front of the doubly linked list.
 void reverse()
          Reverse the list.
 java.lang.String toString()
          Returns the list as a String.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DoublyLinkedList

public DoublyLinkedList()
Constructs a new DoublyLinkedList object with head and tail as null.

Method Detail

isEmpty

public boolean isEmpty()
Returns true if the list is empty false otherwise

Returns:
true if the list empty false otherwise

addCharAtEnd

public void addCharAtEnd(char c)
Add a character node containing the character c to the end of the linked list. This routine does not require a search.

Parameters:
c - -- a single character

addCharAtFront

public void addCharAtFront(char c)
Add a character node containing the character c to the front of the linked list. No search is required.

Parameters:
c - -- a single character

removeCharFromFront

public char removeCharFromFront()
Remove and return the character at the front of the doubly linked list.

Returns:
the character at the front precondition: the list is not empty

removeCharAtEnd

public char removeCharAtEnd()
Remove and return the character at the end of the doubly linked list. No searching is required.

Returns:
the character at the end precondition: the list is not empty

countNodes

public int countNodes()
Counts the number of nodes in the list. We are not maintaining a counter so a search is required.

Returns:
the number of nodes in the doubly linked list between head and tail inclusive

deleteChar

public boolean deleteChar(char c)
Deletes the first occurence of the character c from the list. If the character c is not in the list then no modifications are made. This method needs to search the list.

Parameters:
c - -- the character to be searched for.
Returns:
true if a deletion occurred and false otherwise

toString

public java.lang.String toString()
Returns the list as a String. The class DoubleNode has a toString that will be called from this toString. The String returned must be presented clearly. Null pointers must be represented differently than non-null pointers.

Overrides:
toString in class java.lang.Object
Returns:
a String containing the characters in the list

reverse

public void reverse()
Reverse the list. a -> b -> c becomes c -> b -> a


main

public static void main(java.lang.String[] a)