Public class Node
{
int data;
Node next;
public Node(int data,Node p)
{
this.data=data;
this.next=p;
}
}
What is the meaning of Node next; in the above implementation
Public class Node
{
int data;
Node next;
public Node(int data,Node p)
{
this.data=data;
this.next=p;
}
}
What is the meaning of Node next; in the above implementation
A linked list is a list where every node in the list has both a data value, plus a link to the next node in the list.
In the above code, each node in the list is represented by a Node
object. Each Node
object has a data value (data
) and the next node in the linked list (next
).
Also worth noting is that what you see here is known as a singly-linked list. You can only navigate the list in one direction. There are also doubly-linked lists, where each node has a next
and a previous
. That allows you to navigate the list in either direction.