Linked Lists and Linked List Processing Introduction: This lecture reviews the basics of linked lists. You are expected to understand how to draw linked lists (both full and abbreviated pictures), how to update the drawings by hand simulating code that operates on linked lists (often iterating over linked lists; especially useful for debugging your linked list code), how to add values at the front and rear of a linked list, how to search for and remove a value from a linked list, and how to copy a linked list efficiently. Linked Lists: We will start by looking at a simple class named LN, which we use to represent List Nodes in a singly-linked list (with each object refering to another object from that same class, or to null). This class declares two public instance variables, instead of private ones with accessor/setter methods: note the setters would allow any value to be stored there, so setters aren't of much use (and would increase the syntactic complexity). It also declares one simple constructor; a second one might have just an int i parameter and always set next to null. public class LN { public LN (int i, LN n) {value = i; next = n;} public int value; //Often generalized to a reference type public LN next; } Although not universally agreed upon, I think this style (public instance variables) is easier to write code for, avoiding the extra syntax of doing method calls to examine and set these instance variables. Also, we often declare classes like LN to be nested classes inside another class (in fact, when doing so they are often declared static, and therefore are nested but not inner classes), and therefore they can be manipulated only by the code in the outer class which we also write. We will examine an Object/Variable picture of a linked list built from this class, and a simplified picture that represents all the necessary information, but more compactly (if a bit more ambiguously). You should be able think in terms of both the full and abbreviated pictures. Given such pictures, we should be able to understand how such data structures are accessed when using combinations of .value and .next; e.g., in that data structure, what is the value of x.next.next.value or x.next.next (this last value is a reference)? Every occurence of "." means "follow the reference before the dot to the object that it refers to." And every occurrence of an instance variable after the "." means "focus on the value inside the box for that instance variable" (which might be a reference to follow later). I have found that many students are just "faking" an understanding of how linked structures are accessed and updated. They really don't understand the material in the previous paragraph, or how code accesses and mutates linked lists. They don't follow my recommendations to practice hand-simulating linked list code, so they ultimately have a very hard time writing (and debugging) their linked list code. Iterating over Linked Lists: We will examine the concept of "cursors" and how they unify the processing of arrays (where cursors are ints) and linked lists (where cursors are references): in each case a cursor (a small piece of data) tells "where we are focussed" in a large data structure. With both we can use a standard "for" loop for traversing the entire data structure (focusing on each piece of data in the data structure, one after the other). for array x : for (int i=0; i