Classic Sorting Algorithm -- Merge Sorting
For an int array, write a Merge Sorting Algorithm to sort the array elements.
Given an int array A and the array size n, please return the sorted array.
Test example:
[1, 2, 3, 5, 2, 3], 6
[1, 2, 3, 3, 5]
Class MergeSort {public: int * mergeSort (int * A, int n) {if (A = NULL | n <2) return A; process (A, 0, n-1); return A;} void process (int * A, int left, int right) {if (left> = right) return; int mid = left + (right-left) /2; // divide left and right Processes (A, left, mid); process (A, mid + 1, right); // merge left and right merge (A, left, mid, right);} void merge (int * A, int left, int mid, int right) {int * temp = new int [right-left + 1]; // temporary array int l = left, r = mid + 1; int k = 0; while (l <= mid & r <= right) // select the smaller {if (A [l] <a [r]) in the left and right sub-arrays from the temporary array. else = "" for = "" int = "" I = "0; "left =" "pre =" "> <p> </a [r])>