The following java MySorts class contains a sorting method, which can only sort an array of type
Question:
The following java MySorts class contains a sorting method, which can only sort an array of type double. Edit the sort() method code so that it can sort any List of generic type provided that the generic type is Comparable. The overall sorting procedure should NOT change and no new lines of code are required, just re-writing already existing lines.
MySorts CLASS:
public class MySorts {
public static void sort(double[] arr) {
for (int i=0; i<arr.length-1; i++) {
int indexOfSmallest = i;
// find min in arr[i+1,...]
for (int j=i+1; j<arr.length; j++)
if (arr[j] < arr[indexOfSmallest])
indexOfSmallest = j;
// Swap min with arr[i]
double temp = arr[i];
arr[i] = arr[indexOfSmallest];
arr[indexOfSmallest] = temp;
}
}
Accounting For Governmental And Nonprofit Entities
ISBN: 9781260118858
19th Edition
Authors: Jacqueline Reck, Suzanne Lowensohn, Daniel Neely