The quick sort of the little supercilious eyes

Source: Internet
Author: User

1. Basic Ideas for fast sequencing

1. Select a number from the array as the base number, which is generally the first selected as the base number

2. Compare the remaining data with this benchmark number, put it on one side, and put it on the other side.

3. The array on both sides of the base number repeats the above operation

2. Take the case as evidence

1. Initialize the array as follows

2. Then replace the

The process is as follows:

(1) array from small to large arrangement, now we choose the first number 17 as the base number, from the far right to start than (here must start from the far right, or you can try it), the first number on the right is 14 less than 17, so the index remains in the position of 14 is ready to replace, and then from left to right 3 less than , the index moves one bit to the right, finds that 62 is greater than 17, stops finding and replaces the previous 14, and the result of the first substitution is as follows.

First pair of data after substitution results

(2) Now for the second pair of data substitution, 62 index to the left one bit, found that the value is 1, less than 17, stop find and wait for replacement, 4 is the index to move to the right one bit, the value of 4 is less than 17, continue to move to the right one bit, the value of 56 is greater than 17, and the previous

Second pair of data after substitution results

(3) Third data substitution results

(4) Continue to move the right index, found that the right side of the cable and the left side of the index coincident, reached the position of 13, then use 13 and the base number to exchange.

Four after the data is replaced

(5) Then 17 to the left of an array, 17 to the right of an array, respectively, to perform the above operation, the final result is as follows:

3. On the Code
private static void QuickSort (int arr[],int low,int high) {int L = low;int h = high;int target = Arr[low];while (L < h) {while (L < h && Arr[h] >= target) h--;if (L < h) {int temp = arr[h];arr[h] = arr[l];arr[l] = temp;l++;} while (L < h && Arr[l] <= target) l++;if (L < h) {int temp = arr[h];arr[h] = arr[l];arr[l] = temp;h--;}} if (L > Low) QuickSort (arr, Low, l-1), if (H < high) QuickSort (arr, L + 1, high);}

  

  

The quick sort of the little supercilious eyes

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.