public class QuickSort
{
/**
* Split function (Quick sort function) public static int partition (INT[]N, int. left,int right)
* @param n
* @param left
* @param right
* @return
*/
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;
SYSTEM.OUT.PRINTLN ("Pivot key:" + left);
System.out.println ("Current value:" + arrays.tostring (n));
return left;
}
/*
* 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 void Main (string[] args)
{
int[] Array =
{9,8,7,6,5,4,3,2,1,0};
QuickSort (array, 0, array.length-1);
for (int i = 0; i < array.length; i++)
{
System.out.println (Array[i]);
}
}
}
A quick sort of Java sort