The implementation was relatively straightforward. Each team member was assigned one or two sorting algorithms, and the program would output the complexity and execution time for a randomly generated array at a user-inputted size in a text-based format.
For the quicksort implementation, I used a recursive method following the standard quicksort algorithm steps. The main code was built with ArrayLists, so there was no need to return the sorted value as the parameter was passed by reference—meaning the value passed as the parameter would change when the value in the method was changed.
Here's the QuickSort implementation:
public static void quickSort(ArrayList<Integer> sortMe) {
quickSort(sortMe, 0, sortMe.size()-1);
}
public static void quickSort(ArrayList<Integer> sortMe, int low, int high) {
if (low < high+1) {
int p = partition(sortMe, low, high);
quickSort(sortMe, low, p-1);
quickSort(sortMe, p+1, high);
}
}
public static int partition(ArrayList<Integer> sortMe, int low, int high){
int split = low + 1;
for (int i = split; i <= high; i++) {
if (sortMe.get(i) < sortMe.get(low)) {
swap(sortMe, i, split++);
}
}
swap(sortMe, low, split-1);
return split-1;
}