I am confused about how to add to the front of a linked list.
public void insert(E data) {
if (front == null)
front = new Node(data, null);
else {
Node temp = new Node(data, front);
front = temp;
}
}
This creates a loop. How to avoid this?
I have a LinkedList class that contains the front of a Node, in a variable called the front. I have a Node class in this LinkedList class.
Any help would be greatly appreciated. Thank.
source
share