public void addToHead(IntNode node) {
IntNode temp = _head;
_head = node;
node.setNext(temp);
}
edit:I searched youtube, Nothig there about linkedlist and the heap
When does the garbage collector wipe temp
? I know it should, but can't see where.
I'm having a hard time understanding it. Intuitively I'd just write
_head = node;
I know it's not right, but I feel I need to understand what's going on there with the objects and addresses to get the point...
first line: I create a temp, and point it to the same adress the _head points
seconds line:Now head points to the adress node points, (node.next equals head.next)
third line: now node.next becomes temp..
am i right