PROBLEM: head and tail are global references to the first and last element, respectively, of a singly linked list of integers. Implement  functions for the following prototypes:

public T insertAfter(T tData, T nData)

The two arguments to insertAfter give the element after which the new element is to be inserted and the data for the new element. It should be possible to insert at the beginning of the list by calling insertAfter with NULL as the element argument. These function should return NULL is the operation could not be completed successfully.
Your functions must keep the head and tail pointers updated.

The following answer is based on the previous implemented LinkedList
ANSWER:

public void addToFront(T tData) {
	if(head == null && tail == null) {
		tail = head = new Node(tData);
	} else {
		Node temp = head;
		head = new Node(tData,temp);
	}
	this.length++;
}

public T insertAfter(T tData, T nData) {
	if(tData == null) {
		this.addToFront(nData);
		return nData;
	}
	else {
		Node current = head;
		while(current != null) {
			if(current.getData() == tData) {
				Node newN = new Node(nData);
				newN.setNext(current.getNext());
				current.setNext(newN);
				return newN.getData();
				if(current == tail) tail = newN;
			}
			current = current.getNext();
		}
	}
	return null;
}

Full source: https://github.com/lineker/BackToBasics