The following code is only used by me to review the data structure. The practicality of N is low ~~ Haha:>
/// C ++ template technology to achieve the sort of merging. /// # include <cstdlib> # include <cstring> # include <iostream> # include <stdexcept> // merge operations. // template <typename T> void Merge (T * array, const size_t low, const size_t mid, const size_t high) {If (null = array) {Throw STD :: invalid_argument ("the array parameter is null. ");} // auxiliary group space. T * temparray = new T [High-low + 1]; size_t I, begin1, begin2; for (I = 0, begin1 = low, begin2 = Mid + 1; begin1 <= Mid & begin2 <= high; ++ I) {temparray [I] = array [begin1] <array [begin2]? Array [begin1 ++]: array [begin2 ++];} while (begin1 <= mid) {temparray [I ++] = array [begin1 ++];} while (begin2 <= high) {temparray [I ++] = array [begin2 ++];} for (I = 0; I