2.1 Mystery of the Walrus

Study Guide Link: https://sp21.datastructur.es/materials/lectures/lec3/lec3.html

Notes:

1. The Golden Rule of Equals (GRoE):

3. Challenge Question:

Write a method int get(int i) that returns the ith item in the list.

    /** Write a method get(int i) that returns the ith item of the list. 
     * For example, if L is 5 -> 10 -> 15, then L.get(0) should return 5, 
     * L.get(1) should return 10, and L.get(2) should return 15. */
    public int get(int i){
        if (i == 0){
            return first;
        }
        return rest.get(i - 1);
    }    

2.2 The SLList (Single Linked List) 本质:Add middleman

Study Guide Link: https://sp21.datastructur.es/materials/lectures/lec4/lec4

Notes:

1. Caching:

Saving important data to speed up retrieval. (eg. We add a size variable to the SLList class that tracks the current size, yielding the code below.)

public class SLList {
    ... /* IntNode declaration omitted. */
    private IntNode first;
    private int size;    //create a size variable

    public SLList(int x) {
        first = new IntNode(x, null);
        size = 1;
    }

    public void addFirst(int x) {
        first = new IntNode(x, first);
        size += 1;  // increment for size
    }

    public int size() {
        return size;
    }
    ...
}