CS111 IntListList Contract


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 integer lists; they are created and manipulated by the following class methods:

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 is x and whose tail is L.

public static boolean isEmpty (IntListList L)
Returns true if L is an empty list of integer lists and false if L is an 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 node L. Signals an exception if L is empty.

public static IntListList tail (IntListList L)
Returns the list of integer lists that is the tail component of the list of integer lists node L. Signals an exception if L is empty.

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; 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.

public static String toString (IntListList L)
Returns a string representation of of the integer list L in which the integer list elements are separated by commas and delimited by square brackets. For example, if L1 is a list containing the sequence of integer lists [7,1,4], [6], and [-3,-8], then toString(L1) returns "[[7,1,4],[6],[-3,-8]]".

public static IntListList fromString (String s)
If s is the printed representation of an integer list (i.e., comma separated integer list representations delimited by square brackets), returns an IntListList with 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]. If s is not the printed representation of an integer list, signals an error.