Terms you'll find helpful in completing today's challenge are outlined below, along with sample Java code (where appropriate).

Garbage Collection
This is a form of automated memory management that frees up memory locations that are no longer in use. When a program reserves a block of memory (e.g.: for storing variables), it marks it as 'in-use' and returns a reference to it which is managed by your variable. If a program is poorly written, the reference to that block of memory may be lost or broken; once the reference to that location is lost, the program can neither access the data stored there nor can it store new data there (because the memory was not released back to the program prior to breaking the reference). Java has something called automatic garbage collection; this means you don't have to worry about releasing (deallocating) blocks of memory you no longer need, because the Java garbage collector does it for you. If you're writing in a language that does not have garbage collection, you should make sure you are freeing up the memory that a reference refers to before deleting the reference itself.

Deleting Nodes from Linked Lists
Removing an element from a linked list of nodes is easier than it sounds! In a language with automatic garbage collection (like Java), you simply have to change the next reference from one node so that it points to another node. In the diagram below, we remove n1 by changing n0's next reference so that it points to n2. At this point, there is no longer a named reference to node n1, so Java's garbage collector will delete the orphaned node and free up the memory storing its data. In another language like C++, you should create a temporary reference to the node you are going to orphan, then change the reference from the previous node, and finally delete the node (which you have access to, thanks to the temporary reference you made).


View Practice Challenge