Asp tutorial. net c # Merge Sorting Algorithm Implementation
[Merge Sorting] Algorithm Implementation
I: Start position of the first sequence when merging starts;
S: the size of the pre-merging sequence;
T: size of the merged Sequence
I, I + s-1, I + T-1 defines the boundary of the two merged sequences.
1 // apply the merge algorithm of the previous article to sort Arrays
2 /************************************** ******************************/
3/*********************** [Merge Sorting Algorithm ]********* *********************/
4 /************************************** ******************************/
5 void sort_merge (int array [], int size)
6 {
7 int I; // start position of the first sequence when the merge starts
8 int s; // the size of the pre-merging Sequence
9 int t = 1; // size of the merged Sequence
10
11 while (t <size)
12 {
13 I = 0;
14 s = t;
15 t = 2 * s;
16 while (I + t) <size)
17 {
18 merge (array, I, I + s-1, I + T-1, t); // see merging two subordered array algorithms in the previous article
19 I = I + t;
20}
21 if (I + s <size)
22 {
23 merge (array, I, I + s-1, size-1, size-I );
24}
25}