For an int array, write a quick sort algorithm that sorts the elements of the array.
Given an int array a and the size of the array n, return the sorted array.
Test examples:
[1,2,3,5,2,3],6
[1,2,2,3,3,5]
Class QuickSort {public:int* QuickSort (int* A, int n) {//write code here if (A==null | | n<2) return A; Process (a,0,n-1); return A; } int* Process (int* A, int low,int high) {if (Low < high) {int mid = partition (A, low, high) ; Process (A, low, mid-1),//to a[low...mid-1] to sort the process (a, mid + 1, high), and/or recursively sort the a[mid+1...high] return A; } int partition (int* a,int low,int High) {///fast-order algorithm partitioning process, divides the array into left and right two sub-arrays int pivot = A[low]; int i = low; int j = high; if (Low < high) {when (I < j) {while (I < J && Pivot < = A[j]) j--;//Find the element that is smaller than the base number if (I < j) A[i] = A[j]; while (I < J && Pivot >= A[i]) i++;//Find the element that is larger than the base number if (I < j) A[j] = A[i]; } A[i] = pivot; } return i; }};
Classic sorting algorithm--Quick sort