I always get null value. I am beginner in this language. Thank you for understanding.
class Node{
int data;
Node next;
Node(int value){
data = value;
}
}
void addNode(Node headNode, int aValue){
Node newNode = new Node(aValue); //creating new node
newNode.next = headNode; // pointing the next to headNode
headNode = newNode; // updating the head Node
}
void main(){
Node head = Node(1);
addNode(head,2);
addNode(head,3);
print(head.next.data); //here I always get null
}
Your help will truely be appreciated.