ListOfListsLab.java
file in the ListOfLists folder
are skeletons for the following five methods:
public static IntList mapSum (IntListList nss);
IL.sum(IntList L)
to each IntList in nss.
mapSum([ ]) = [ ] mapSum([[ ]]) = [0] mapSum([[1]]) = [1] mapSum([[1], [ ]]) = [1, 0] mapSum([[2, 1], [1], [ ]]) = [3, 1, 0] mapSum([[3, 2, 1], [2, 1], [1], [ ]]) = [6, 3, 1, 0] mapSum([[4, 3, 2, 1], [3, 2, 1], [2, 1], [1], [ ]]) = [10, 6, 3, 1, 0] mapSum([[2, 4, 8], [5, 10], [3, 6, 9]]) = [14, 15, 18]
public static IntListList mapMapDouble (IntListList nss);
Returns the result of applying IL.mapDouble(IntList L)
to each
IntList in nss.
mapMapDouble([ ]) = [ ] mapMapDouble([[ ]]) = [[ ]] mapMapDouble([[1]]) = [[2]] mapMapDouble([[1], [ ]]) = [[2], [ ]] mapMapDouble([[2, 1], [1], [ ]]) = [[4, 2], [2], [ ]] mapMapDouble([[3, 2, 1], [2, 1], [1], [ ]]) = [[6, 4, 2], [4, 2], [2], [ ]] mapMapDouble([[4, 3, 2, 1], [3, 2, 1], [2, 1], [1], [ ]]) = [[8, 6, 4, 2], [6, 4, 2],[4, 2], [2], [ ]] mapMapDouble([[2, 4, 8], [5, 10], [3, 6, 9]]) = [[4, 8, 16], [10, 20], [6, 12, 18]]
public static IntListList subsequences (IntList ns);
Returns a list of all subsequences of nss. A subsequence of nss is a list that
is obtained from nss by deleting zero or more elements and maintaining the
relative order of the undeleted elements. The order of components lists in the
result returned by subsequences does not matter.
subsequences([ ]) = [[ ]] subsequences([1]) = [[1], [ ]] subsequences([2, 1]) = [[2, 1], [2], [1], [ ]] subsequences([3, 2, 1]) = [[3, 2, 1], [3, 2], [3, 1], [3], [2, 1], [2], [1], [ ]] subsequences([4, 3, 2, 1]) = [[4, 3, 2, 1], [4, 3, 2], [4, 3, 1], [4, 3], [4, 2, 1], [4, 2], [4, 1], [4], [3, 2, 1], [3, 2], [3, 1], [3], [2, 1], [2], [1], [ ]]
public static IntListList combination (IntListList nss);
combination([ ]) = [[ ]] combination([[ ]]) = [ ] combination([[1]]) = [[1]] combination([[2, 1]]) = [[2], [1]] combination([[3, 4], [2, 1]]) = [[3, 2], [3, 1], [4, 2], [4, 1]] combination([[2, 4, 8], [5, 10], [3, 6, 9]]) = [[2, 5, 3], [2, 5, 6], [2, 5, 9], [2, 10, 3], [2, 10, 6], [2, 10, 9], [4, 5, 3], [4, 5, 6], [4, 5, 9], [4, 10, 3], [4, 10, 6], [4, 10, 9], [8, 5, 3], [8, 5, 6], [8, 5, 9], [8, 10, 3], [8, 10, 6], [8, 10, 9]]Note: For combination, you may choose what to return in the case that nss is empty. It is useful to define mapMapPrepend in order to do this problem.
public static IntListList mapMapPrepend (IntList ns, IntListList nss);
Returns the result of applying mapPrepend(int n, IntListList nss)
of
each integer in ns to each IntList in nss.
mapMapPrepend([ ], [ ]) = [ ] mapMapPrepend([ ], [[ ]]) = [ ] mapMapPrepend([ ], [[1]]) = [ ] mapMapPrepend([ ], [[2, 1]]) = [ ] mapMapPrepend([ ], [[3, 4], [2, 1]]) = [ ] mapMapPrepend([1], [ ]) = [ ] mapMapPrepend([1], [[ ]]) = [[1]] mapMapPrepend([1], [[1]]) = [[1, 1]] mapMapPrepend([1], [[2, 1]]) = [[1, 2, 1]] mapMapPrepend([1], [[3, 4], [2, 1]]) = [[1, 3, 4], [1, 2, 1]] mapMapPrepend([2, 1], [ ]) = [ ] mapMapPrepend([2, 1], [[ ]]) = [[2], [1]] mapMapPrepend([2, 1], [[1]]) = [[2, 1], [1, 1]] mapMapPrepend([2, 1], [[2, 1]]) = [[2, 2, 1], [1, 2, 1]] mapMapPrepend([2, 1], [[3, 4], [2, 1]]) = [[2, 3, 4], [2, 2, 1], [1, 3, 4], [1, 2, 1]] mapMapPrepend([3, 2, 1], [ ]) = [ ] mapMapPrepend([3, 2, 1], [[ ]]) = [[3], [2], [1]] mapMapPrepend([3, 2, 1], [[1]]) = [[3, 1], [2, 1], [1, 1]] mapMapPrepend([3, 2, 1], [[2, 1]]) = [[3, 2, 1], [2, 2, 1], [1, 2, 1]] mapMapPrepend([3, 2, 1], [[3, 4], [2, 1]]) = [[3, 3, 4], [3, 2, 1], [2, 3, 4], [2, 2, 1], [1, 3, 4], [1, 2, 1]]
IntList
and IntListList
methods are available
via the abbreviations IL and ILL, respectively.
mapPrepend
method has been provided for you.
As you can see, there are buttons which allow us to create IntList and IntListLists
and buttons which allow us to invoke the methods in the lab on those lists. Below
is the result of creating an IntList and IntList list and then hitting one of the
method buttons:
A working version of this applet is available in the Test folder. The
skeleton for this applet is in the file LOLApplet.java
. Follow the
guidelines below for completing the applet. Remember that creating an applet can
be divided into two phases: implementing the layout and implementing the
behavior.