The following code is only used by me to review the data structure. The practicality of N is low ~~ Haha:>
/// C ++ template Technology for direct insertion sorting. // # include <cstdlib> # include <cstring> # include <iostream> template <typename T> void insertionsort (T * array, const size_t count) {T temp; for (size_t I = 1, J; I <count; ++ I) {for (j = I, temp = array [J]; 0 <J & temp <array [J-1]; -- j) {array [J] = array [J-1];} array [J] = temp ;}} //// test // int main (void) {char sztest [] = "Insertion Sort Algorithm test case! "; Int iarrtest [] = {23, 12, 2,123, 72, 35, 49, 51, 83, 94, 65}; const size_t int_arr_size = sizeof (iarrtest) /sizeof (iarrtest [0]); insertionsort (sztest, strlen (sztest); insertionsort (iarrtest, int_arr_size); STD: cout <sztest <STD: Endl; for (size_t I = 0; I <int_arr_size; ++ I) {STD: cout <iarrtest [I] <"";} STD: cout <STD:: Endl; return exit_success ;}