Package testsortalgorithm;
public class QuickSort {
public static void Main (string[] args) {
int [] array = {49,38,65,97,76,13,27};
QuickSort (array, 0, array.length-1);
for (int i = 0; i < Array.Length; i++) {
System.out.println (Array[i]);
}
}
/* First write the algorithm according to the array for the data prototype, and then write the extensibility algorithm. Array {49,38,65,97,76,13,27}
* */
public static void QuickSort (Int[]n, int. Left,int right) {
int pivot;
if (left < right) {
Pivot as pivot, compared to small elements on the left, compared to large elements in the right
Pivot = partition (n, left, right);
Recursive calls to left and right arrays are quickly sorted until the order is completely correct
QuickSort (n, left, pivot-1);
QuickSort (n, pivot + 1, right);
}
}
public static int partition (INT[]N, int. Left,int right) {
int pivotkey = N[left];
Pivot is selected and will never change, eventually in the middle, before the small rear big
while (left < right) {
while (left < right && N[right] >= pivotkey)--right;
Move the element smaller than the pivot to the lower end, at which point the right bit is equal to NULL, waiting for the lower-than-pivotkey number to fill up
N[left] = N[right];
while (left < right && N[left] <= pivotkey) ++left;
Move the element larger than the pivot to the high end, at which point the left bit is equal to empty, waiting for a higher number to be smaller than the pivotkey.
N[right] = N[left];
}
When left = = right, complete a quick sequence, the left bit is equivalent to empty, waiting for PivotKey to fill up
N[left] = PivotKey;
return left;
}
}
Java Quick Sort Implementation