--- tags: Setup-Summer21 --- # Lecture 9 Setup/Prep At the end of lecture 8, we had a `LinkList` class with two methods: `addFirst` and `contains`. This lecture, we will look at two more common list methods: `addLast` and `length`. At this point, you should be able to write a basic version of these methods, so we've provided initial versions in the starter code. Our goal for this lecture is to see how to use fields and field-mutation to improve the running time of these two methods. ## Prep Download [the starter code for lecture 9](https://cs18-summer-2021.github.io/static/classes/9/lec09.zip). In this version, we are using an `EmptyList` class rather than `null` for the empty list, just so you see different ways of implementing lists. - The starter code has two interfaces: `IList` and `IListInternal`. Why are there two interfaces? - Think about adding field(s) to the existing classes that would reduce the running-time of `length` to constant. What field(s) would you add and to which classes? How will they be maintained as we add elements to the list? - Think about how you would maintain these fields within the `remEltOnce' method. During lecture, we will also add fields to make `addLast` run in constant time.