<PRE name = "code" class = "CPP"> <span style = "background-color: RGB (255,255,255 ); "> // insert sorting /// O (N ^ 2). When one element is inserted in the incremental sequence, O (n) # include" sort. H "Void issort (void * data, int size, int esize, INT (* compare) (const void * key1, const void * key2) {int I, J; int * A = (int *) data; int * key; // request space for the key if (Key = (int *) malloc (sizeof (char )))! = NULL) {return;} // initialize JJ = 1; while (j <= size) // J is the element to be sorted, move {// key as the cache memcpy (Key, & A [J], sizeof (INT); I = J-1; // I starts from the left position of J while (I <= J) {If (compare (Key, & A [I]) <0) // A [J] <A [I] {memcpy (& A [I + 1], & A [I], sizeof (INT )); // move the entire array to the right by position I --;} // insert a [J] to the correct position memcpy (& A [I + 1], key, sizeof (INT); j ++;} Free (key); Return ;}</span>
Algorithm Refinement (1) -- insert sorting