Question: 8 . Consider the following class. / * * A class that sorts an array of Integer objects from * largest to smallest using a
Consider the following class.
A class that sorts an array of Integer objects from
largest to smallest using a selection sort.
public class Sorter
private Integer a;
public SorterInteger arr
a arr;
Swap ai and aj in array a
private void swapint i int j
implementation not shown
Sort array a from largest to smallest using selection sort.
Precondition: a is an array of Integer objects.
public void selectionSort
for int i ; i alength ; i
find max element in ai to an
Integer max ai;
int maxPos i;
for int j i ; j alength; j
if maxcompareToajmax less than aj
max aj;
maxPos j;
swapi maxPos; swap ai and amaxPos
If an array of Integer contains the following elements, what would the array
look like after the third pass of selectionSort, sorting from high to low?
A
B
C
D
E
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
