CMPS 144L
Activity: Array-based representation of Positional Lists

    pred     contents     succ      frontLoc
   +----+  +----------+  +----+     +------+
 0 |  6 |  |   null   |  | -1 |     |   4  |
   +----+  +----------+  +----+     +------+
 1 |  8 |  |   APE    |  |  3 |
   +----+  +----------+  +----+
 2 |    |  |          |  |  9 |
   +----+  +----------+  +----+     availLoc
 3 |  1 |  |   DOG    |  |  6 |      +---+
   +----+  +----------+  +----+      | 7 |
 4 | -1 |  |   BUG    |  |  8 |      +---+
   +----+  +----------+  +----+
 5 |    |  |          |  | -1 |
   +----+  +----------+  +----+
 6 |  3 |  |   PIG    |  |  0 |
   +----+  +----------+  +----+
 7 |    |  |          |  |  2 |
   +----+  +----------+  +----+
 8 |  4 |  |   COW    |  |  1 |
   +----+  +----------+  +----+
 9 |    |  |          |  |  5 |
   +----+  +----------+  +----+
The diagram to the right shows a concrete array-based representation of a positional list, as discussed during lecture (and in web pages). (The contents of memory cells left blank are irrelevant.)

1. Enumerate the animals occupying the list, from first to last.

2. Suppose that the remove() method were applied to a cursor that was positioned at the node containing DOG. Describe exactly what changes would be made to the concrete representation of the list. That is, for every memory cell whose value would change, identify that cell and tell what its new value would be. (E.g., "pred[9] gets the value 2.") Recall that the purpose of the instance variable availLoc is to indicate the topmost location on the "available location stack".

3. Ignoring the effects of the previous problem, suppose that the insert() method were applied to a cursor that was positioned at the node containing DOG for the purpose of inserting EMU. As in the previous problem, describe exactly what changes would be made to the concrete representation of the list. (Recall that a newly-inserted node becomes the predecessor of the cursor's position.)