The IntListList class describes
immutable linked lists whose elements are integer lists.
A list of integer lists is defined recursively as either
Lists of integer lists are immutable in the
sense that the head or tail of a list node cannot be changed after
the list node has been created (via the prepend() method).
There are no public constructor or instance methods for list of integer
lists; they are created and manipulated by the class methods below.
By default, an IntListList class method is invoked via
IntListList.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 IntListList ILL; // declare but never initialize this variable.
Class Methods
public static IntListList empty()
Returns an empty list of integer lists.
public static IntListList prepend (IntList x, IntListList L)
Returns a new list of integer lists node whose head isxand whose tail isL. Returns a new list of integer lists node whose head isxand whose tail isL. From another perspective, returns a list whose length is one more than the length ofLand whose elements arexfollowed by the elements ofL, in order.
public static boolean isEmpty (IntListList L)
ReturnstrueifLis an empty list of integer lists andfalseifLis a list of integer lists node.
public static IntList head (IntListList L)
Returns the integer list that is the head component of the list of integer lists nodeL. Signals an exception ifLis empty.
public static IntListList tail (IntListList L)
Returns the list of integer lists that is the tail component of the list of integer lists nodeL. Signals an exception ifLis empty.
public static String toString (IntListList L)
Returns a string representation of the list of integer listsLin which the integer list elements are separated by commas and delimited by square brackets. For example, ifL1is a list containing the sequence of integer lists whose printed representations are [7,1,4], [6], and [-3,-8], thentoString(L1)returns"[[7,1,4],[6],[-3,-8]]".
public static IntListList fromString (String s)
Ifsis the printed representation of a list of integer lists (i.e., comma separated integer list representations delimited by square brackets), returns anIntListListwith that representation. For example,fromString("[[7,1,4],[6],[-3,-8]]")returns an 3-element list of integer lists whose elements are the integer lists[7,1,4],[6], and[-3,-8]. Ifsis not the printed representation of an integer list, signals an error.