Java Quick Sort Demo with array 0 bits as datum and last one as Datum

Source: Internet
Author: User
Tags benchmark

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 (Low

Operation Result:

  

Java Quick Sort Demo with array 0 bits as datum and last one as Datum

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.