CMPS 144L Fall 2019
Lab #11: Hodgepodge

Activity #1: Array-based Positional List Representation

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: Sorting Points with the help of Comparators

Provided are these complete "artifacts":

Task #1: Complete the development of DistToOrigComparator, which implements the java.util.Comparator interface. It is intended to define an ordering upon objects of the PointIn2Space class consistent with this rule:

Point P is "less than" point Q iff P is closer to the origin than Q is.

To test your work, feed the contents of the points.txt file to the SelSortTester application.

Task #2: Develop, from scratch, a LexicographicComparator class that, like DistToOrigComparator, defines an ordering upon objects of the PointIn2Space class. However, the ordering that it defines should be consistent with this rule:

Point P is "less than" point Q iff either P's x coordinate is less than Q's or, in case they are the equal, P's y-coordinate is less than Q's.

In other words, points are ordered by their x-coordinates, with ties broken by considering their y-coordinates.

Having developed the class, test it by adding a line of code to the SelSortTester application. Specifically, at the end of the main() method, insert a second call to the readSortPrint() method, different from the first in that the second actual parameter should be an instance of LexicographicComparator (rather than DistToOrigComparator).


Activity #3: Recursion

Modify the SelectionSorter class (that you used in the previous activity) so that its second sort() method is recursive. Base your code upon the observation that, to sort an array segment a[low..high), it suffices to:

To test your work, you can use the SortIntegers application.