this blog is no longer updated, many other wonderful content please visit my Independent Blog
High-speed sequencing is a very important sorting algorithm, but when I was learning, I found that there are no particularly good examples on the Internet, so I wrote one.
Get your hands on your own.
Package Sort;import Java.util.random;public class QuickSort {@SuppressWarnings ("unused") Public boolean Inittestarray ( Int[] testarray) {//Initialize testarrayif (Testarray = = null) return false; Random random = new random (), for (int i = 0; i < testarray.length; i++) {Testarray[i] = Random.nextint (200);} return true;} public boolean Printtestarray (int[] testarray) {//print content in Testarray if (Testarray = = null) return false;for (int i = 0; I < ; Testarray.length; i++) {System.out.print (Testarray[i] + ",");} System.out.println (); return true;} public static Boolean QuickSort (int[] testarray, int left, int. right) {if (testarray==null) return false;if (left < right {int pivotpos = Quicksort.partition (Testarray, left, right); Quicksort.quicksort (Testarray, left, pivotpos-1); Quicksort.quicksort (Testarray, Pivotpos + 1, right);} return true;} public static int partition (int[] Testarray, int. Low, int.) {int i = low, j = high, pivot = Testarray[low],temp=0;whil E (i < J) {while (I < J && TestarRAY[J] >= pivot) j--;while (i < J && Testarray[i] <= pivot) i++;temp = testarray[i];testarray[i] = Testarra Y[J];TESTARRAY[J] = temp;} Testarray[low] = Testarray[i];testarray[i] = Pivot;return i;} public static void Main (String args[]) {int[] Testarray = new INT[20]; QuickSort QuickSort = new QuickSort (); Quicksort.inittestarray (Testarray); System.out.println ("Pre-order:"); Quicksort.printtestarray (Testarray); Quicksort.quicksort (Testarray, 0, testarray.length-1)) System.out.println ("Sorting Error!"); System.out.println ("After sorting:"); Quicksort.printtestarray (Testarray);}}
High-speed Sequencing Java language implementation