Introduction to direct Insertion sort

Source: Internet
Author: User

Sequencing is an important operation in computer programming, and its function is to rearrange any sequence of data elements (or records) into an ordered sequence of keywords.

What we've known before is probably bubble sort, select sort, but in contrast, these two methods are not very efficient, in this article I briefly introduce the direct insertion of the sort.

The direct insertion sort is a simple sort method that inserts a record into an ordered table that is sorted so that a new one is obtained. An ordered table with an additional number of records.

For example, the initial arrangement of a set of records to be sorted looks like this:

R ((), R (), R (), R (), R (), R (27) ...

Suppose that during the sort process, the first 4 records are rearranged in the order in which they are incremented by keyword, form an ordered sequence of 4 records: {R (), R (), R (), R (97)} first insert the fifth record of the initial sequence above into this recorded record, You first look in a good sequence to determine where R (76) should be inserted, and then insert.

void Dir_sort (SqList L)     
{     
    int i, J;     
    for (i = 2; i < l.length i++)     
    {     
        if (LT (L.r[i].data, L.r[i-1].data))     
        {     
            l.r[0] = l.r[i];     
            L.r[i] = l.r[i-1];     
            for (j = i-2; LT (L.r[0].data, l.r[j].data); j--)     
            {     
                l.r[j+1] = l.r[j];     
            }     
                     
            L.R[J+1] = l.r[0];     
        }     
    for (i = 1;i <= l.length; i++)     
        printf ("%d", l.r[i].data);     
    printf ("\ n");     
}

This article is from the "Late Evening" blog, please be sure to keep this source http://yiluohuanghun.blog.51cto.com/3407300/879937

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.