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]