CS62, Lecture 13

    ArrayList

    When we talked about the use of arrays, we noted that we can create arrays of any fixed size, but can't change size aside from creating an entirely new array.

    Built-in interface java.util.List specifies a sequence of elements. The operations available include those in our library interface IndexList includes most of the methods from java.util.List.

    ArrayList implementation

    The class java.util.ArrayList implements List and fixes the problems of running out of space, by increasing the size of the underlying array whenever it runs out of space.

    The library class IndexList provides an implementation very similar to java.util.ArrayList.

    The authors present an analysis using "cyberdollars" to show the average cost is less than 3n -- and hence O(n) to add elements to a vector.

    Node lists

    Now we would like to implement node lists in such a way that the user can't tell what kind of list we are implementing. We will do this by hiding the kind of node behind a very bland interface called Position that nodes can implement, and interface PositionList for a list using positions.

    The classes DNode and NodePositionList implement these interfaces.