The IntListOps class contains some commonly used auxiliary class methods
that manipulate integer lists.
All of these can easily be written in terms of the class methods from
the IntList contract; they are provided here for convenience.
Also for convenience, the IntListOps class also supplies all
of the IntList class methods.
By default, an IntListOps class method is invoked via
IntListOps.methodName(args), but this can
be abbreviated to IL.methodName(args)
by including the following "magical" declaration in the body
of a class:
public static IntListOps IL; // declare but never initialize this variable.
Because IntListOps includes both core IntList
methods and auxiliary methods, the above declaration enables
using the prefix IL. to access all of these class methods.
Class Methods
For convenience, the
public static IntList append (IntList L1, IntList L2)
Returns an integer list whose length is the sum of the lengths ofL1andL2and whose elements are all the elements ofL1, in order, followed by all the elements ofL2, in order.
public static boolean equals (IntList L1, IntList L2)
ReturnstrueifL1andL2have the same length and the same elements in the same order; otherwise returnsfalse. Note that theequalsmethod behaves differently than==on lists, which determines if two list nodes were created by the same call toprepend. For instance, ifLis the list[1,2,3], thenL.equals(prepend(1,tail(L)))istrue, butL == prepend(1,tail(L))isfalse.
public static IntList fromTo (int lo, int hi)
Returns a list of the integers fromloup tohi, inclusive. Returns the empty list iflois greater thanhi.
public static boolean isMember (int n, IntList L)
Returnstrueifnis an element of listLandfalseotherwise.
public static int length (IntList L)
Returns the length ofL-- i.e., the number of non-empty list nodes inL.
public static IntList postpend (IntList L, int n)
Returns a list whose length is one more than the length ofLand whose elements are all the elements ofL, in order, followed byn.
public static IntList reverse (IntList L)
Returns a list whose length is the same as that asLand whose elements are all the elements ofLin reverse order.
IntListOps class also provides all the
class methods of the IntList class:
public static IntList empty() public static IntList prepend (int n, IntList L) public static boolean isEmpty (IntList L) public static int head (IntList L) public static IntList tail (IntList L) public static String toString (IntList L) public static IntList fromString (String s)