Problem 13
What will the aSort method given below print if sortThisArray[]{130, 763, 248, 884, 970,
525, 505,}. The method printArray prints the contents of sortThisArray.
public void aSort() {
aSort(sortThisArray, 0, sortThisArray.length - 1);
}
private void aSort(int[] array, int low, int high) {
if(low < high) {
int pi = partitionV2(array, low, high);
aSort(array, low, pi - 1);
aSort(array, pi + 1, high);
}
}
private int partition(int array[], int low, int high) {
int j = low;
int pi = low + ((high - low) / 2);
int temp = array[high];
int pivot = array[pi];
array[high] = pivot;
array[pi] = temp;
System.out.println();
System.out.println("The pivot is:" + pivot);
for(int i = low; i < high; i++) {
if(array[i] < pivot) {
temp = array[i];
array[i] = array[j];
array[j] = temp;
j++;
}
}
array[high] = array[j];
array[j] = pivot;
printArray();
return j;
}