Lowest price ever! Learn Generative AI for 48% less!
Get my discount+ 1
Node in a linked list
the thing that confuses me the most is when there's an node class. I still don't understand it. I know it has Node next and whatever data you're trying to pass for example int data how is it used?
3 Answers
+ 8
assuming its a single linked node...
think of a node as a square with a value inside and a null pointer to the right
[ 5 | null ]
when we create a new node, we will do the same thing. value and point to null, but this time, the previous node points to the new node
[ 5 | ]->[ 7 | null ]
and one more node.
Note the last node on a single link always points to null
[ 5 | ]->[ 7 | ]->[ 420 | null ]
the first and last are known as head and tail, respectively
+ 8
and to get data from a list that is over 3 nodes, you must traverse.
Not easy like an array where array[4] gets 5th element
+ 1
see, I understand the concept, but it's the code that I don't understand