Solved

Consider the Swap Method Shown Below from the SelectionSorter Class

Question 45

Multiple Choice

Consider the swap method shown below from the SelectionSorter class. If we modified it as shown in the swap2 method shown below, what would be the effect on the sort method?
Private static void swap(int[] a, int i, int j)
{
Int temp = a[i];
A[i] = a[j];
A[j] = temp;
}
Private static void swap2(int[] a, int i, int j)
{
A[i] = a[j];
A[j] = a[i];
}


A) There would be no effect.
B) Some array elements would be overwritten.
C) It would sort the array in reverse order.
D) It would still be correct, but run a little faster.

Correct Answer:

verifed

Verified

Unlock this answer now
Get Access to more Verified Answers free of charge

Related Questions