Class LinkedList<E>

java.lang.Object
  extended by LinkedList<E>

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


Constructor Summary
LinkedList()
          Creates an empty linked list.
 
Method Summary
 boolean add(int position, Node<E> newNode)
          Adds a node to the list; the new node is at the given position.
 boolean delete(int position)
          Deletes the node at the given position.
 E getData(int position)
          Returns the data at the given position of the linked list.
 void printList()
          Prints the elements of the list, one per line.
 int search(E target)
          Searches the list for an element equal to the given element.
 int size()
          Returns the number of nodes in the list.
 
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 E getData(int position)
Returns the data at the given position of the linked list. If the position is out of range, returns null. Remeber that position 0 is the first position in the list.

Parameters:
position - Position of data to be returned
Returns:
Data at the given position

add

public boolean add(int position,
                   Node<E> newNode)
Adds a node to the list; the new node is at the given position. Returns true if the add is successful, false otherwise.

Parameters:
position - Position of new node
newNode - New node to be added to the list
Returns:
True if add is successful, false otherwise.

delete

public boolean delete(int position)
Deletes the node at the given position. Returns true if successful, false otherwise.

Parameters:
position - Position to delete
Returns:
True if successful, false otherwise.

size

public int size()
Returns the number of nodes in the list.

Returns:
Number of nodes in the list.

printList

public void printList()
Prints the elements of the list, one per line.


search

public int search(E target)
Searches the list for an element equal to the given element. Returns the index of the first found element, or -1 if the element is not found.

Returns:
Index of the first found element, or -1 if the element is not found.