CS111 IntListListOps Contract

The IntListListOps class contains some commonly used auxiliary class methods that manipulate lists of integer lists. All of these can easily be written in terms of the class methods from the IntListList contract; they are provided here for convenience. Also for convenience, the IntListListOps class also supplies all of the IntListList class methods.

By default, an IntListListOps class method is invoked via IntListListOps.methodName(args), but this can be abbreviated to ILL.methodName(args) by including the following "magical" declaration in the body of a class:

public static IntListListOps ILL; // declare but never initialize this variable.

Because IntListListOps includes both core IntListList methods and auxiliary methods, the above declaration enables using the prefix ILL. to access all of these class methods.

Class Methods

public static IntListList append (IntListList L1, IntListList L2)
Returns an integer list whose length is the sum of the lengths of L1 and L2 and whose elements are all the elements of L1, in order, followed by all the elements of L2, in order.

public static boolean equals (IntListList L1, IntListList L2)
Returns true if L1 and L2 have the same length and the same elements in the same order (where sameness of elements is determined by the equals method of the IntList class); otherwise returns false. Note that the equals method behaves differently than == on lists, which determines if two list nodes were created by the same call to prepend. For instance, if L is the list [[7,1,4],[6],[-3,-8]], then L.equals(prepend(IntList.fromString("[7,1,4]"),tail(L))) is true, but L == prepend(IntList.fromString("[7,1,4]"),tail(L)) is false.

public static boolean isMember (IntList x, IntListList L)
Returns true if x is an element of list L and false otherwise. Equality of elements is determined by the equals method of the IntList class.

public static int length (IntListList L)
Returns the length of L -- i.e., the number of non-empty list nodes in L.

public static IntListList postpend (IntListList L, IntList x)
Returns a list whose length is one more than the length of L and whose elements are all the elements of L, in order, followed by x.

public static IntListList reverse (IntListList L)
Returns a list whose length is the same as that as L and whose elements are all the elements of L in reverse order.

public static void prettyPrint (IntListList L)
Display a printed representation of L in which each integer list element appears on its own line.

For convenience, the IntListListOps class also provides all the class methods of the IntListList class:
public static IntListList empty()
public static IntListList prepend (IntList x, IntListList L)
public static boolean isEmpty (IntListList L)
public static IntList head (IntListList L)
public static IntListList tail (IntListList L)
public static String toString (IntListList L)
public static IntListList fromString (String s)