4.1 Коды для сортировки вставками

typedef int T; /* type of item to be sorted */

typedef int tbllndex;      /* type of subscript */

#define compGT(a,b)   (a > b)

void insertSort(T *a,  tbllndex lb,  tbllndex ub) {

T t;

tbllndex i, j;

/**************************

*    sort array a[lb..ub] * **************************/

for  (i = lb + 1; i <= ub; { t = a[i];

/* Shift elements down until */ /* insertion point found. */

for  (j = j >= lb && compGT(a[j],  t); j--)

a[j+1]  = a[j];

/* insert */ a[j+1]  = t;

}

}