array[]是元素序列,其中从索引p开始到q位置,按照升序排列,同时,从(q+1)到r也已经按照升序排列,merge()函数将把这两个已经排序好的子序列合并成一个排序序列。结果放到array中。 */ /** * 0 <= p <= q < r, subarray array[p..q] and array[q+1..r] are already sorted. * the merge() function merges the two sub-arrays into one sorted array. */ void Merge(int array[], int p, int q, int r) { int i,k; int begin1,end1,begin2,end2; int* temp = (int*)malloc((r-p+1)*sizeof(int)); begin1 = p; end1 = q; begin2 = q+1; end2 = r; k = 0; while((begin1 <= end1)&&( begin2 <= end2)) { if(array[begin1] <= array[begin2]) { temp[k] = array[begin1]; begin1++; } else { temp[k] = array[begin2]; begin2++; } k++; } while(begin1<=end1 || begin2<=end2) { if(begin1<=end1) { temp[k++] = array[begin1++]; } if(begin2<=end2) { temp[k++] = array[begin2++]; } } for (i = 0; i < =(r - p); i++) array[p+i] = temp[i]; free(temp); }JavaScript语言function　merge(left, right) { var　result=[]; while(left.length>0 && right.length>0) { if(left