Understanding linear linked list
- by ArtWorkAD
Hi,
I have some problems understanding the linear linked list data structure. This is how I define a list element:
class Node{
Object data;
Node link;
public Node(Object pData, Node pLink){
this.data = pData;
this.link = pLink;
}
}
To keep it simple we say that a list are linked nodes so we do not need to define a class list (recursion principle).
My problem is that I am really confused in understanding how nodes are connected, more precisely the sequence of the nodes when we connect them.
Node n1 = new Node(new Integer(2), null);
Node n2 = new Node(new Integer(1), n1);
What is link? Is it the previous or the next element? Any other suggestions to help me understanding this data structure?