Understanding linear linked list
Posted
by
ArtWorkAD
on Stack Overflow
See other posts from Stack Overflow
or by ArtWorkAD
Published on 2011-01-01T19:37:07Z
Indexed on
2011/01/01
19:54 UTC
Read the original article
Hit count: 171
data-structures
|recursion
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?
© Stack Overflow or respective owner