Class LinkedList<T>

java.lang.Object
  extended by LinkedList<T>

public class LinkedList<T>
extends java.lang.Object


Constructor Summary
LinkedList()
          Creates an empty linked list.
 
Method Summary
 boolean add(int index, T newData)
          Adds the given data to the linked list.
 boolean delete(int index)
          Deletes data at position index from the linked list.
 T getData(int index)
          Returns the data at the given index of the linked list.
 int getLength()
          Gets the length (i.e., number of data elements) in the list.
 void printList()
          Prints all the data in the linked list to the screen, in order of index.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LinkedList

public LinkedList()
Creates an empty linked list.

Method Detail

getData

public T getData(int index)
Returns the data at the given index of the linked list.

Parameters:
index - Index of data to be returned, 0 = head.
Returns:
Data at the given index.

add

public boolean add(int index,
                   T newData)
Adds the given data to the linked list. The new data becomes the data at the given index. Data previously at index is at index+1, at index+1 is at index+2, and so on. In order to add data to the list, there must exist data at index-1. Returns true if the add is successful, false otherwise.

Parameters:
index - Index where the new data is added
newData - New data to add to the list
Returns:
True if add is successful, false otherwise

delete

public boolean delete(int index)
Deletes data at position index from the linked list. Data previously at index+1 is now at position index, at index+2 is now at position index+1, and so on. There must be data at position index in order for the delete to be successful. Returns true if the delete is successful, false otherwise.

Parameters:
index - Index of data to be deleted.
Returns:
True if delete is successful, false otherwise.

getLength

public int getLength()
Gets the length (i.e., number of data elements) in the list.

Returns:
Length of the list.

printList

public void printList()
Prints all the data in the linked list to the screen, in order of index.