Sharding algorithm-fast sorting and Merge Sorting

Source: Internet
Author: User

Sharding algorithm-fast sorting and Merge Sorting

 

 

Fast sort http://blog.csdn.net/morewindows/article/details/6684558 analysis: Data Structure p186. important when the source file order complexity is o (n2). In this case, bubble sort is the best, and fast sort in disorder is the best method. Void QuickSort (int * a, int l, int r) {if (r <= l) {return;} int I = l; int j = r; int x = a [I]; // a [l] That is, a [I] is the first pitfall. // Number of pitfall fields while (j> I) {// select a [I] while (a [j] >=x & j> I) {j --;} from the right to the left --;} if (j> I) {a [I] = a [j]; // enter a [j] in a [I, a [j] forms a new pitfall I ++;} // from left to right find a number greater than or equal to x to fill in a [j] while (a [I]
 
  
I) {I ++;} if (j> I) {a [j] = a [I]; // enter a [I] in a [j, a [I] forms a new pitfall j --;} // when exiting, I is equal to j. Fill x in this pitfall. A [I] = x; // method of separation and control QuickSort (a, l, I-1); QuickSort (a, I + 1, r );}
 
Merge sort http://blog.csdn.net/morewindows/article/details/6678165 // there will be two sequential series a [first... mid] And a [mid... last] merge. Void mergearray (int a [], int first, int mid, int last, int temp []) {int I = first; int n = mid; int j = mid + 1; int m = last; int k = 0; while (I <= n & j <= m) {// compare the first number of two series, when the number is small, the number is obtained first, and then the number is deleted in the corresponding series. if (a [I]

 

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.