// CS111 Lab 13 Spring 2000 public class ListOfListsLab { // hack for being able to refer to IntList and IntListList methods // by abbreviations IL and ILL respectively private static IntListOps IL; private static IntListListOps ILL; public static IntList mapSum (IntListList nss) { if (ILL.isEmpty(nss)) { return IL.empty(); } else { return IL.prepend(IL.sum(ILL.head(nss)), mapSum(ILL.tail(nss))); } } public static IntListList mapMapDouble (IntListList nss) { if (ILL.isEmpty(nss)) { return ILL.empty(); } else { return ILL.prepend(IL.mapDouble(ILL.head(nss)), mapMapDouble(ILL.tail(nss))); } } public static IntListList subsequences (IntList ns) { if (IL.isEmpty(ns)) { return ILL.prepend(IL.empty(),ILL.empty()); } else { IntListList partialSubsequences = subsequences(IL.tail(ns)); return ILL.append(mapPrepend(IL.head(ns), partialSubsequences), partialSubsequences); } } public static IntListList combination (IntListList nss) { if (ILL.isEmpty(nss)) { return ILL.prepend(IL.empty(), ILL.empty()); } else { return mapMapPrepend(ILL.head(nss), combination(ILL.tail(nss))); } } public static IntListList mapMapPrepend (IntList ns, IntListList nss) { if (IL.isEmpty(ns)) { return ILL.empty(); } else { return ILL.append(mapPrepend(IL.head(ns), nss), mapMapPrepend(IL.tail(ns), nss)); } } public static IntListList mapPrepend (int n, IntListList nss) { if (ILL.isEmpty(nss)) { return ILL.empty(); } else { return ILL.prepend(IL.prepend(n, ILL.head(nss)), mapPrepend(n, ILL.tail(nss))); } } }