Home

算法导论第二章

10 Mar 2013 by LelouchHe

代码

插入排序

void insert_sort(int a[], int n)
{
    int i, j;
    int key;
    for (j = 1; j < n; j++)
    {
        key = a[j];
        for (i = j - 1; i >= 0 && a[i] > key; i--)
        {
            a[i + 1] = a[i];
        }
        a[i + 1] = key;
    }
}

合并排序