I.AlgorithmThoughts:
Insert sort algorithm idea: Compare the number of inserts with the number of sorted arrays and insert the values according to the size relationship to keep the original size order. (Traverse from the end of the array to the array header)
Binary insert: first, compare the original ordered intermediate number with the new inserted number, then Insert the new number size into the half of the array, and then take the number in the middle of the array again, until the number of arrays obtained is one, the number after the last number is removed, and the new number is placed at the index.
2. simulation source code:
# Include <iostream> using namespace STD; // directly Insert the sorted int arr [15] = {11, 22, 45, 71 }; int list [15]; void binaryinsertsort (INT arr [], int size) {int low, high, temp, value; For (INT I = 0; I <size; I ++) {value = arr [I]; Low = 0; high = I-1; while (low <= high) {temp = (low + high)/2; if (list [temp] <value) Low = temp + 1; elsehigh = temp-1;} For (int K = I; k> = low; k --) {list [k] = list [k-1];} list [low] = value ;}} void show () {for (Int J = 0; j <15; j ++) cout <list [J] <""; cout <Endl;} int main () {binaryinsertsort (ARR, 15 ); cout <"after half insert:" <Endl; show ();}