Quick Sort (Ascending)

Source: Internet
Author: User

1, the algorithm think

By a trip to sort the data to be sorted into separate two parts, where the left part of all the data is smaller than the right part of all the data, and then this method of the two parts of the data are quickly sorted, the entire sorting process can be recursive, so as to achieve the entire data into an ordered sequence.

2. Algorithm implementation

     Packagetest;  Public classQuickSort { Public Static voidMain (string[] args) {int[] n ={1,3,6,2,9,6,8,7}; Quicksort (N,0,7);  for(inti:n) {System.out.print (i+ "\ T"); }                        }           Public Static voidQuicksortint[] n,intLeftintRight ) {              intDP; if(left<Right ) {DP=partition (N,left,right); Quicksort (N,LEFT,DP-1); Quicksort (N,DP+1, right); }          }           Public Static intPartitionint[] n,intLeftintRight ) {              intPivot =N[left];  while(left<Right ) {                   while(left<right&&n[right]>=pivot) right--; if(left<Right ) N[left++]=N[right];  while(left<right&&n[left]<=pivot) left++; if(left<Right ) N[right--]=N[left]; } N[left]=pivot; returnLeft ; }      }  

Quick Sort (Ascending)

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.