Java sorting an array by using quick sort

Source: Internet
Author: User

1 Package com.yzy.test;2 3  Public classTest {4 5     /**6 * @param args7      */8      Public Static voidMain (string[] args) {9         int[] Array = { +, -, +,6565,3424, A,6523,345 };TenArraySort (Array,0, Array.Length-1); One          for(intI:array) { ASystem. out. print (i +" "); -         } -     } the  -     //Quick Sort Method -     Private Static voidArraySort (int[] Array,intLowindex,intHighindex) { -         intLow =Lowindex; +         intHigh =Highindex; -         intmid; +         if(Lowindex <Highindex) { A              while(Low <=High ) { atMid = array[(Lowindex + highindex)/2]; -                  while(Low < Highindex) && (Array[low] <mid)) { -++Low ; -                 } -                  while((High > Lowindex) && (Array[high] >mid)) { ---High ; in                 } -                 if(Low <=High ) { to Wrap (array, low, high); +++Low ; ---High ; the                 } *             } $             if(Low <Highindex) {Panax Notoginseng ArraySort (array, low, highindex); -             } the             if(High >Lowindex) { + arraysort (array, lowindex, high); A             } the         } +  -     } $  $     //Exchanging array elements -     Private Static voidWrapint[] Array,intLowintHigh ) { -         //TODO auto-generated Method Stub the         inttemp =Array[low]; -Array[low] =Array[high];WuyiArray[high] =temp; the     } -}

Technical points: quick Sorting is an improvement on the sorting of bubbles, which is relatively fast. The basic idea is to divide the sorted data into two separate parts, one by one, and all of the data in part is smaller than the rest of the data, and then the two parts of the data are sorted quickly by this method. The entire sorting process can be done recursively, so that the entire data becomes an ordered sequence.

Java sorting an array by using quick sort

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.