Quick Sort QuickSort

Source: Internet
Author: User

Learning Links: Sitting on the toilet see algorithm: Quick Sort

Java code:

1 classquicksort{2     int[] Sortans;3     4 QuickSort () {}5     6QuickSort (int[] nums) {7QSort (nums,0,nums.length-1);8sortans=nums;9     }Ten      One     protected voidQSort (int[] Nums,intAintb) { A         if(a<C) { -             intpos=patition (nums,a,b); -QSort (nums,a,pos-1); theQSort (nums,pos+1, b); -         } -     } -     intPatition (int[] Nums,intAintb) { +         intinit=A; -          while(b>a) { +              while(Nums[b]>nums[init] && b>a) { Ab--;//Right Sentry left shift at             } -              while(Nums[init]>=nums[a] && b>a) {//Nums[init]>=nums[a] -a++;//left Sentry Right move through "=, in the first cycle, the Sentinel leaves the base number -             } -             if(a<b) Swap (NUMS,A,B); -         } inSwap (NUMS,INIT,A);//Base Number Homing -         returnA; to     } +      -     voidSwapint[] Nums,intAintb) { the         inttmp=Nums[a]; *nums[a]=Nums[b]; $nums[b]=tmp;Panax Notoginseng     } -       PublicString toString () { the          inti; +String str=NewString (""); A           for(i=0;i<sortans.length;i++) str+=string.valueof (Sortans[i]) + ""; thestr+= "\ n"; +          returnstr; -      } $       $}

Quick Sort QuickSort

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.