CSE 214 Lecture 7: Linked Lists Continued
Document Summary
Linked lists are dynamic compared to arrays where data could be stored in different blocks of memory. Adding node to the head of a list. Beware of the things you are not supposed to do which could cause you to lose reference to the original list. The cursor is a reference to the link object the user is acting on. Private intnode cursor; // reference to what the user is currently working on. New nodes are added into the link as needed. There are distinct references between references and an actual node (object). For example, head, tail, and cursor are all references. Adding node to head of list newnode = new intnode(element); newnode. setlink(head); Always set head to newnode last or else you will lose the reference to the original linked list. What happens is that when head is set to null, the java gc will pick it up and remove the elements.