I am new to Java. I have a been trying linked list using class but I encountered some problem.
class Node
{
int data;
Node next;
}
class LinkedListOperations
{
public static void main(String args[])throws IOException
{
Node element = new Node();
Node head;
.......
.......
.......
}
}
As per my knowledge, the statement Node element = new Node()
creates an object called element consisting of 2 fields namely next and data, but I am not sure what does Node head
do?
What will be stored in Node head
?
Will there be only next
field or data
field or both the fields?
Can someone explain using an example so that I can have a clear picture?