Section2Problems 4 - 9 Write a method runningTotal returns...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 9. \ '\ Write a method runningTotal returns that a new Arraylntlist that contains a running Iist. In other words, the i-th 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 j-s empty, the given with the capacity resuft should be an empty list. returns whether or not a list a method isPairwi-seSorted that of l-0. Write (true if it is, false otherwise) . A list is integers is pairwise sorted pair pai-rwise sorted if each successive of numbers is in sorted considered (non-decreasing) 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, al-I 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 j-rst n va.Iues from a list of integers. For example, variable sequence of values: call-ed 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

This note was uploaded on 11/03/2009 for the course CSE 143 taught by Professor Sr during the Spring '08 term at University of Washington.

Ask a homework question - tutors are online