QuickSort Program
Description
This program uses the quick sort algorithm to sort an array of random integers.Associated Concepts:
Quick Sort
Algorithm:
main method:
quickSort method definition:
partition method definition:
Create an array with random integers.
Print the unsorted array elements.
Call the method quickSort() to sort the array, and pass the array, the left most index, the right most index as the arguments.
Print the sorted array elements.
Print the unsorted array elements.
Call the method quickSort() to sort the array, and pass the array, the left most index, the right most index as the arguments.
Print the sorted array elements.
quickSort method definition:
Call partition() method to get the index j which creates a partition at j,
and pass the array, the left most index, and the right most index
as the arguments.
Call quickSort() on the left partition and on the right partition recursively.
The process stops once there is only one element left in the sub-array.
At this point, the array is sorted.
Call quickSort() on the left partition and on the right partition recursively.
The process stops once there is only one element left in the sub-array.
At this point, the array is sorted.
partition method definition:
The Partition() method creates a partition at index j:
elements on the left <= x (pivot)
elements on the right >= x (pivot)
elements on the right >= x (pivot)