CS210 Tues., Apr 11
Note hw4 is posted, pa5 coming.  Also lab5 is posted.

We were working on Chap 15, near end:
ListIterator for ArrayList

Iterators--recall that the current position is between two elements of the list (positions 1, 2, ..., n-1), or before all elements (position 0), or after al (position n).

Recall that the expectedModCount of ListIterator object is set when it is constructed to the current modCount from outer object, the ArrayList.

When the iterator's own remove() is called, it increments expectedModCount so that the incremented modCount of its outer object will still match with its own expectedModCount, so this iterator will continue to be usable, i.e., won't throw.  It's OK for an interator to do remove, next, remove, ..., and in fact this is a way to do ArrayList.clear().

We looked at an example in detail  ArrayList with elements 2, 4, 6, and a ListIterator starting at position 0, doing a next(), then a remove().  We watched the field values of ArrayList and ArrayListIterator change as this happened.

Chap. 16
Stacks implemented with arrays--straigthforward, read in book.

Queues implemented with arrays--elements tend to march down the array, need to wrap around and start over in the array.  Tricky to keep track of this but "increment" operation helps.  Study pics in book.

Stacks implemented with linked lists.  We studied the ListNode class definition--note the recursion of having a ListNode ref inside a ListNode object.  This allows the ListNodes to be chained together by refs.   "push" is easy--study pic, see refs being updated.  "pop" is easy too.

Queues implemented with linked lists. Same basic idea as stacks implemented by linked lists, here need two refs from the base "Queue" object.

Chap 17

Note that Chap 17 starts out with singly-linked lists, but these are not as generally useful as doubly-linked lists such as our JDK LinkedList, so skip sections 17.1 and 17.2 and start at section 17.3, on doubly-linked lists.  

I drew a picture of a LinkedList with 3 elements.  It has the 3 element objects, plus two dummy elements at start and end, and 5 little connector objects with next and prev refs plus the element ref to hold the whole thing together.  There is a base "LinkedList" object, from which there are refs to the two dummy connectors at the start and end of the list.  This is something like Figure 17.15, except this figure has put the element values into the connector objects, but really they are hanging off them by refs.

We looked at the Node class definition on pg. 581, which shows the 3 refs of the little connector objects.  Again, like the ListNode of Chap 16, this is a recursive data structure.  

We looked at the fields of LinkedList to see the refs to the start and end connector objects, called beginMarker and endMarker.  We also noted the "theSize" and "modCount" fields.

Weiss's LinkedList class extends AbstractCollection, as does his ArrayList class, simplifying the JDK class setup.  As we predicted when looking at AbstractCollection, isEmpty() and toArray() are handled by AbstractCollection for this class, but most of the important methods are overridden by LinkedList.