您的位置:首页 > 其它

插入排序

2016-03-03 20:38 183 查看
#include <stdio.h>

#include <stdlib.h>

void InsertionSort(int a[], int n)

{

    int in, out, temp;

    for (out = 1; out < n; out++)

    {

        temp = a[out];

        in = out;

        while (a[in-1]>=temp && in>0)

        {

            a[in] = a[in-1];

            in--;

        }

        a[in] = temp;

    }

    return;

}

void main()

{

    int i;

    int a[10] = { 2, 4, 6, 8, 0, 1, 3, 5, 7, 9 };

    InsertionSort(a, 10);

    for (i = 0; i < 10;i++)

    {

        printf("%d\n", a[i]);

    }

    system("pause");

    return;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: