Section2Problems 2 - 3-10r For problems in cLass discussed...

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: 3-10r For problems in cLass discussed €rssume that lecture: you are writing a method for the Arraylntl.j-st public cl,ass Arraylntlist t private int elementData; private int size; <methods> ) Unless otherwise class in solving 3. noted, assume that the problem. you may not call any other methods of the value as a parameter and that Write that takes an integer a method removeAll You can assume of the given value from the List. removes al-I occurrences and remove exists takes an index as a parameter that that a method called at the given index removes the value that Write a method An integers. appears before Thus, second. at inversions a wariable that Then the 1). . print would print (4, 3) (.4 , 2 .. l (4, 1) (3,21 (3, 1) (2, 1) is just one possible correct so this can appear in any order, The inversions can format exactly, but the inversions You must reproduce this output. 4 in the Iist Notice that any given number (e.9., appear in any order. inversions, because there might be different above) can produce several (aII of I, 2, and 3 in the it, that are less than it numbers after several has no duplicates. You may assume that the list example) . printlnversions lists inversions in a list of all that of numbers where the first inversion is defined as a pair is greater than the but the first the second in the list, for a sorted list such as (1' 2, 3, 4', there are no would produce no output. Suppose and printlnversions aII, in reverse order, as in (4, 3, }ist called stores a list caII: Inversions () ; 4. 2, many inversions: 5. of the most returns the number of occurrences Write a method maxCount that Because the list list of integers. value in a sorted occurring frequently whj-ch will make it will duplicates be grouped together, all will be sorted, a variable For example, suppose that called to count duplicates. easier the following seguence of values: stores Iist lrr 3r 4r 7r 7r 7r 7r 9r 9r 11r 13, L4, 14, L4, L6, L6r 18r 19, !9r 191 13, occur just once (1, 3, 4,11, This list has vaLues that (14, 19) (9, :..6), values that occur three times twice occur (7). Therefore, the following occurs four times value that l-ist . maxCount o 18), values that and a single calI: return 4 to indicate that the most should that wil-I 4 times. It is possible value, but that doesn't affect occurring For not the value. returning the count, every value wiII occur then in the list, is empty, your method If the list be 1. freguently value occurs occurring for the most frequently be a tie the outcome because you are just exampfe, if there are no duplicates once and the maximum would exactly 0. should return ...
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