1. First, we need to introduce the algorithm for merging two sorted tables. Suppose there is an array A [1... M], p, q, and r are three of its indexes, and there is 1 percentile p limit q <r limit m. Two sub-arrays A [p... Q], A [q + 1... R] in ascending order, we need to reschedule the position of the elements in A so that the sub-array A [p... R] are also arranged in ascending order. This is to merge A [p... Q] And A [q + 1... R. The merge algorithm is as follows. Two pointers s and t are used to point to A [p] And A [q + 1] respectively during initialization, and an empty array B [p... R] for the temporary storage. Each time the comparison elements A [s] and A [t] are compared, small elements are added to B. If they are the same, A [s] is added. Then update the pointer. If A [s] returns A [t], then s ++; otherwise, t ++, it ends when the condition s = q + 1 or t = r + 1 is set. In the first case, the array A [t... Add the remaining elements in r] to B. In another case, the array A [s... Q] Add the remaining elements to B. Finally, the array B [p... R] Copy and add A [p... R]. The pseudocode is as follows: /*************************************** **************************************** * ** algorithm: merge input: array A [1... m], p, q, and r are three of its indexes, with 1 <= p <= q <r <= m. Two sub-arrays A [p... q], A [q + 1... r] Output in ascending order: merge two sub-arrays A [p... q], A [q + 1... r] new array A [1... m] *********************************** **************************************** * ***/s = p; t = q + 1; k = p; while (s <= q & t <= r) {if (A [s] <= A [t]) {B [k] = A [s]; s ++;} else {B [k] = A [t]; t ++;} k ++ ;} if (s = q + 1) {B [k... r] = A [t... r];} else {B [k... r] = A [s... q];} A [p... r] = B [p... r]; 2. merge and sort /************************************* **************************************** * ***** algorithm: mergesort input: A [1... n] Output: array A [1... n] mergesort (A, 1, n ); **************************************** **************************************** * **/process mergesort (, low, high) if (low