com.fun.tips
Class DoublyLinkedList<T>

java.lang.Object
  extended by com.fun.tips.DoublyLinkedList<T>
Type Parameters:
T - The type of the data items stored in the list
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Iterable<T>

public class DoublyLinkedList<T>
extends java.lang.Object
implements java.lang.Cloneable, java.lang.Iterable<T>

A doubly linked list implementation


Constructor Summary
DoublyLinkedList()
           
 
Method Summary
 void appendElement(T e)
          Append an element to the list
 DoublyLinkedList<T> clone()
          Clone the list (data items will not be cloned)
 T getElementAt(int index)
          Get the element at the specified index
 T getFirstElement()
          Get the first element of the list
 T getLastElement()
          Get the last element of the list
 int getSize()
          Get the size of the list
 boolean insertElementAt(T e, int index)
          Insert an element at the specified index
 boolean isEmpty()
          Check if the list is empty
 java.util.Iterator<T> iterator()
           
static void main(java.lang.String[] args)
           
 void prependElement(T e)
          Prepend an element to the list
 boolean removeElementAt(int index)
          Remove the element at the given index
 boolean removeFirstElement()
          Remove the first element from the list
 boolean removeLastElement()
          Remove the last element from the list
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DoublyLinkedList

public DoublyLinkedList()
Method Detail

appendElement

public void appendElement(T e)
Append an element to the list

Parameters:
e - element to append

clone

public DoublyLinkedList<T> clone()
Clone the list (data items will not be cloned)

Overrides:
clone in class java.lang.Object
Returns:
the cloned list

getElementAt

public T getElementAt(int index)
Get the element at the specified index

Parameters:
index - index of the element
Returns:
The element at the specified index, or null of not present

getFirstElement

public T getFirstElement()
Get the first element of the list

Returns:
the first element of the list, null if not present

getLastElement

public T getLastElement()
Get the last element of the list

Returns:
the last element of the list, null if not present

getSize

public int getSize()
Get the size of the list

Returns:
the size of the list

insertElementAt

public boolean insertElementAt(T e,
                               int index)
Insert an element at the specified index

Parameters:
e - Elemenent to insert
index - index at which the element should be inserted (in range [0..size()])
Returns:
true if inserted, false if the index was not valid

isEmpty

public boolean isEmpty()
Check if the list is empty

Returns:
true if the list is empty, false otherwise

iterator

public java.util.Iterator<T> iterator()
Specified by:
iterator in interface java.lang.Iterable<T>

main

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

prependElement

public void prependElement(T e)
Prepend an element to the list

Parameters:
e - element to prepend

removeElementAt

public boolean removeElementAt(int index)
Remove the element at the given index

Parameters:
index - index of the element to remove ([0..size()-1])
Returns:
true if removed, false if the index was invalid

removeFirstElement

public boolean removeFirstElement()
Remove the first element from the list

Returns:
true if removed, false if the list was empty

removeLastElement

public boolean removeLastElement()
Remove the last element from the list

Returns:
true of removed, false if the list was empty

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object