CMPS 144L Spring 2019
Lab #11: Positional Lists with Cursors

Activity #1

For this part, put your answers into a plain text file called "Activity1.txt" and submit it to your lab11_dir folder.

1. The following shows a concrete array-based representation of a positional list, as discussed during lecture. (The contents of memory cells left blank are irrelevant.) Enumerate the animals occupying the list, from first to last.

    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 |
   +----+  +----------+  +----+

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.


Activity #2

The files you are going to need are

In the PL_With_C_Utils class are five stubbed methods that you are to attempt to complete. They are clearly marked by STUB! and their comments should suffice to explain their intended behavior. Several other (complete) methods are present, in part to give you examples that you can use as models. When you are finished, you should submit the source code file of this class to your lab11_dir folder. (Again: Submit the .java file, not the .class file!)

PLC_Utils_Tester is a Java application that you can use to test your work. You are free to modify it to suit your testing needs.

The remaining Java classes implement the "Positional List with Cursors" abstraction and are not to be modified, unless you get permission from your TA. To view the full array of methods available to list and cursor objects, see the PL_With_C and PLC interfaces. (Unless you are interested in the gory details of implementation, don't view the contents of PL_With_C_ViaArray.)

Notes: