Insertion Sort

Reference:

  1. Sorting algorithms/Insertion sort

//a: Array
//n: size of array
void insertion_sort(int *a, int n)
{
    int i, j, t;
    for(i=1; i<n; i++) {
        t = a[i];
        for(j=i; j>0 && t<a[j-1]; j--) {
            a[j] = a[j-1];
        }
        a[j] = t;
    }
}

results matching ""

    No results matching ""