There are several optimization methods for the fast sorting algorithm: The selection of datum points, minus the unnecessary switching positions, optimization of fractional groups, optimization of recursion (in the case of short array length, the direct insertion algorithm is OK)
Time Complexity (NLOG2N)
public class QuickSort {
public static void Main (string[] args) {
int a[]={1,3,5,2,7,7,4,9};
Sort (A, 0, 7);
for (int i = 0; i < a.length; i++) {
System.out.print (A[i]);
}
}
public static void Sort (Int. a[],int Low,int High) {
When int point=a[low];//begins, the Datum point is at the beginning of the array
if (LowPoint=patertion (A,low,high);
Sort (a,low,point-1);//recursion Left
Sort (a,point+1,high);//Recursive Right
}
}
private static int patertion (int[] A, int low, int. high) {
int Point=a[low];
while (Lowwhile (Lowhigh--;
}
A[low]=a[high];
Swap (A,low,high);//Our exchange can become an assignment
while (Lowlow++;
}
A[high]=a[low];
Swap (A,low,high),///Our exchange can become an assignment, the last low position of the point, after the end of the assignment back to A[low]=point;
}
A[low]=point;
return low;
}
private static void Swap (int[] A, int low, int. high) {
int temp;
Temp=a[high];
A[high]=a[low];
A[low]=temp;
// }
//
}
Sorting algorithm (Quick sort)