Package Util;public class Pub {public static void Beforesort (int[] arr) {System.out.println (' before sort: '); for (int I:arr {System.out.print (i+ "");} System.out.println ();} public static void Aftersort (int[] arr) {System.out.println (' after sort: '); for (int i:arr) {System.out.print (i+ "");}}}
The 0-bit benchmark code is as follows:
Package Swap;import Java.util.arrays;import util. Pub;public class Fastsort {/** * @param args */public static void main (string[] args) {int[] a={1,38,65,97,76,13,27}; Pub.beforesort (a); Quick (a); Pub.aftersort (a);} private static int Getmiddle (int[] Arr,int left,int right) {int base=arr[left]; The key point when starting from the first number on the left as the base, the right start to judge while (Left<right) {while (left<right&&arr[right]>=base) {right--;} Arr[left]=arr[right];while (left<right&&arr[left]<=base) {left++;} Arr[right]=arr[left];} Arr[left]=base;return Left;//system.out.println (left);} private static void QuickSort (int[] A, int low, int. high) {if (Low
Operation Result:
At the end of the benchmark, the code is as follows:
Package Swap;import Java.util.arrays;import util. Pub;public class Fastsortreverse {/** * @param args */public static void main (string[] args) {int[] a={1,38,65,97,76,13,2 7}; Pub.beforesort (a); Quick (a); Pub.aftersort (a);} private static int Getmiddle (int[] Arr,int left,int right) {//key point Select which side of the array to begin to compare as the base point, you need to start judging from the other end, or else the error will be replaced. int Base=arr[right]; while (Left<right) {while (left<right&&arr[left]<=base) {left++;} Arr[right]=arr[left];while (left<right&&arr[right]>=base) {right--;} Arr[left]=arr[right];} Because this method always overwrites the original base base number, you need to find the right place to put the base number. Arr[left]=base;return Left;//system.out.println (left);} private static void QuickSort (int[] A, int low, int. high) {if (LowOperation Result:
Java Quick Sort Demo with array 0 bits as datum and last one as Datum