Quick sort java version, quicksort
Import java. util. Random;
Public class test {
Public static void main (String [] args)
{
Int [] arr = generatenumbers (10 );
Show (arr, "before sort :");
Quicksort (arr, 0, arr. length-1 );
Show (arr, "after sort :");
}
Static void quicksort (int [] arr, int l, int r)
{
If (l> = r) return;
Int I = l; int j = r;
Int region = arr [I]; // Region
While (I <j)
{
// From right to left find the number less than Algorithm
While (I <j & arr [j]> = bytes) j --;
If (I <j) arr [I ++] = arr [j];
// Now the empty position is arra [j]
// From left to right find the number bigger than Interval
While (I <j & arr [I] <= random) I ++;
If (I <j) arr [j --] = arr [I];
}
// When I = j then the empty position is I/j so we shoshould set the Parameter
Arr [I] = role;
// Recursive call the method
Quicksort (arr, l, I-1 );
Quicksort (arr, I + 1, r );
}
Static int [] generatenumbers (int length)
{
Random r = new Random ();
Int [] arr = new int [length];
For (int I = 0; I <length; I ++)
Arr [I] = r. nextInt (100 );
Return arr;
}
Static void show (int [] arr, String msg)
{
System. out. println (msg );
For (int I = 0; I <arr. length; I ++)
System. out. print (arr [I] + "\ t ");
System. out. println ();
}
Java uses quicksort to sort an array containing 10 numbers.
Class QSort {public static void main (String [] args) {quicksort qs = new quicksort (); int data [] = {1, 3, 5, 7, 9, 2, 4, 6, 8, 0}; qs. data = data; qs. sort (0, qs. data. length-1); qs. display () ;}} class quicksort {public int data []; private int partition (int sortArray [], int low, int hight) {int key = sortArray [low]; while (low
Quicksort sorts by values of two-dimensional arrays (c/c ++/java)
Fast sorting is a Sort idea. It is not just an array of dimensions. You must be able to determine the boundary, growth, and reduction methods,
Processing the corresponding situation separately on the dimension boundary is equivalent to providing the overloaded ++ and --, personal understanding, for reference only
You can also create a one-dimensional array to store data, sort the data on one-dimensional, and copy the data.