Binary insertion sort)

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.