Binary insertion sort is the sort of insert. Algorithm Because in the sorting algorithm process, elements are constantly inserted into the sorted sequence in sequence. Because the first half is divided into sorted columns, we do not need to look for insertion points in sequence. We can use the half-lookup method to speed up the search for insertion points.
The specific operation of the semi-insertion sorting algorithm is to find the insertion point when a new element is inserted into an sorted array, set the first element of the area to a [low] and the last element to a [High]. During the round comparison, the elements to be inserted and a [m] are M = (low + high)/2. If it is smaller than the reference element, select a [low] To M-1] as the new insert area (that is, high = s-1 ), otherwise, select a [M + 1] to a [High] as the new insert area (that is, low = m + 1) Until lowlow; j --)
B [J] = B [J-1];
B [low] = T;
}
}
BelowCodeIs incorrect:
Void binarysearchinsertion (INT numbers [], const int N)
{
Int middle = 0;
For (INT I = 1; I middle; k --)
Numbers [k] = numbers [k-1];
Numbers [low] = temp; // use numbers [high + 1] = temp here; or
}
}
Note that the following code cannot be written:
For (int K = I; k> middle; k --)
Numbers [k] = numbers [k-1];
Numbers [low] = temp; // use numbers [high + 1] = temp here; or
Corrected the blog's answer, http://blog.csdn.net/seuzyq/archive/2009/10/05/4634373.aspx
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/seuzyq/archive/2009/10/05/4634373.aspx