Fast sort algorithm (Java)

Source: Internet
Author: User

The basic idea of the fast sorting algorithm is to divide the pending records into two separate parts through a sort of sequencing, and some of the key words of the records are smaller than those of the other records, then the two parts of the records can be sorted separately to achieve the order of the whole sequence.

classpartitionsort{ Public voidPint[] a) {//PrintOut results for(inti=0;i<a.length;i++) {System.out.print (A[i]+" ");    } System.out.println (); }     Public intPartition (int[] A,intLowintHigh ) {//Find the ordinal of the middle position and returninttemp = A[low];//set The low number is middle number         while(low<High ) {              while(Low//This is the can not lost =,else are die loophigh--;//High position-1} A[low]=a[high];//< Middle number, make it in front of middle number             while(lowA[low]) { Low++; } A[high]=A[low]; } A[low]=temp; returnLow ; }     Public voidQSort (int[] A,intLowintHigh) {//Recurrence method to come true using recursive methods to sort        if(a.length>0){            if(low<High ) {                intPartition =Partition (A,low,high); QSort (A,low,partition-1); QSort (A,partition+1, high); }        }    }     Public Static voidMain (String args[]) {int[] A = {38,49,65,97,76,13,27,49}; Partitionsort P=NewPartitionsort (); P.qsort (A,0,a.length-1);    P.P (a); }}

Fast sort algorithm (Java)

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.