Java sort--[Quick Sort]

Source: Internet
Author: User

1  PackageCom.array;2 3  Public classSort_quick {4     /*5 * Project name: Quick sort;6 * Project requirements: Using the Java array to sort, and the use of fast sorting algorithm;7 * SEVCK;8      */9      Public voidSortintLeftintRightintarray[]) {Ten         intL =Left ; One         intR =Right ; A         intPirot = array[(left + right)/2]; -         inttemp = 0; -          while(L <r) { the              while(Array[l] < Pirot && L >=Left ) -l++; -              while(Array[r] > Pirot && r <=Right ) -r--; +             if(L >=R) -                  Break; +temp =Array[l]; AARRAY[L] =Array[r]; atARRAY[R] =temp; -         } -  -         if(L = =r) { -l++; -r--; in         } -  to         if(Left <R) + sort (left, r, array); -         if(Right >l) the sort (L, right, array); *     } $ Panax Notoginseng      Public Static voidMain (string[] args) { -         intArr1[] = {7, 3, 2, 9, 15, 1, 14 }; theSort_quick QS =NewSort_quick (); +Qs.sort (0, Arr1.length-1, arr1); A  theSystem.out.println ("The current array is:"); +  -          for(inti = 0; i < arr1.length; i++) { $System.out.print ("" +arr1[i]); $         } -     } -}

This need to say, before the quick line has been written wrong, debugging for a long time did not solve, (the results found when not careful-write + +).

See for a long while did not see, arr1.length-1 how can become 7 ... Find chicken Brother asked, instant solved, also was spit Groove code write good rotten. It's not good to see.

But after watching the chicken brother is really self-sigh, good study of his coding style ...

Java sort--[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.