Unformatted text preview: 9. \ '\ Write a method runningTotal returns that a new Arraylntlist that contains a running Iist. In other words, the ith total of the original value in the new list should store the sum of eLements 0 through i of the original Iist. For example, Lf a variable list stores the following sequence of values: 12, and the 3, 5, 4,'7, 15, is 20, 7) following callIist2 Iist2 14, 2], made: list. runningtotal store 531 should the () ; following sequence of values: Arraylntlist Then the 12, variable 5, 10, should 36, 56, The original list should not be changed by the method. The new list have the same capaclty as the original. Remember that there is a for Arraylntlist that takes a capacity as a parameter: constructor >= 0 / / pre : capacity post.: constructs an empty list // (int public ArrayfntList capacity) If the original list js empty, the given with the capacity resuft should be an empty list. returns whether or not a list a method isPairwiseSorted that of l0. Write (true if it is, false otherwise) . A list is integers is pairwise sorted pair pairwise sorted if each successive of numbers is in sorted considered (nondecreasing) For example, if a variable cal1ed list order. stores the following sequence of values: [3, then the list 8, 2, 5, L9, 24, 3, 0, 4, 4, 8, 205, 42) following call: () pairs list true because the successive are of this (L9, 24), (3, 0), (4, 4), (8, 205) . Notice 5), at the end had no effect on the result because it had instead ff the list stored the following: 5, 3r 0, 42r 308, 409, L9, t7,2r 4] . isPairwiseSorted should return the value (3, 8), (2, alI sorted: value 42 that the extra is not part of a pair. [1, 9,3, L7r 4,28, the value false because the pair then the method should return [19, ]7l is is so short that it has no pairs, not in sorted If a list order. then it is considered sorted. to be pairwise 11. Writ.e a method t"*olrl"tona n as a parameter that takes an integer removes the f jrst n va.Iues from a list of integers. For example, variable sequence of values: called list stores this [8, and the Iist. then it 142, t7, 9, 24, 42, call 3, is 8] made: and that if a followinq removeFront (4) ; should 3, 8l values in the list have been same order as in the original removed list. and the store the followinq values after the call: four Notice the first that other values appear in the ...
View
Full Document
 Spring '08
 SR
 Englishlanguage films, Subroutine, Elementary mathematics, Arraylntlist, variable list stores

Click to edit the document details