Here is the code for selection sort (for an array of ints):
public static void selectionSort( int [ ] arr )
{
int temp;
int max;
for ( int i = 0; i < arr.length - 1; i++ )
{
max = indexOfLargestElement( arr, arr.length - i );
System.out.println( "max = " + max );
temp = arr[max];
arr[max] = arr[arr.length - i - 1];
arr[arr.length - i - 1] = temp;
}
}
public static int indexOfLargestElement( int [ ] arr, int size )
{
int index = 0;
for ( int i = 1; i < size; i++ )
{
if ( arr[i] > arr[index] )
index = i;
}
return index;
}
We are running the following code:
int [ ] numbers = { 10, 6, 4, 8 };
selectionSort( numbers );
Show what the output statement in the selectionSort method outputs. The question is not what the array looks like at the end; we know it is sorted in ascending order.
Correct Answer:
Verified
ma...
View Answer
Unlock this answer now
Get Access to more Verified Answers free of charge
Q69: Consider the following class:
public class Radio
{
private double
Q70: Write the code to compute and output
Q71: An array, numbers, has been declared and
Q72: An array, letters, has been declared and
Q73: Code a method that returns an int
Q75: Consider the following two-dimensional array:
String [ ][
Q76: The variable cities is an ArrayList of
Q77: The variable numbers is a two-dimensional array
Q78: The ArrayList method trimToSize has the following
Q79: The ArrayList method indexOf has the following
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents