IntList Contract

The IntList class describes immutable linked lists of integers. An integer list is either the empty list or a (non-empty) list node with a head component that is an integer and a tail component that is another integer list. The 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 IntList empty()
Returns an empty integer list.

public static IntList prepend (int n, IntList L)
Returns a new integer list node whose head is n and whose tail is L.

public static boolean isEmpty (IntList L)
Returns true if L is an empty integer list and false if L is an integer list node.

public static int head (IntList L)
Returns the integer that is the head component of the integer list node L. Signals an exception if L is empty.

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