6 typedef int T; /* type of item to be sorted */
7 typedef int tblIndex; /* type of subscript */
9 #define compGT(a,b) (a > b)
11 void insertSort(T *a, tblIndex lb, tblIndex ub) {
15 /**************************
16 * sort array a[lb..ub] *
17 **************************/
18 for (i = lb + 1; i <= ub; i++) {
21 /* Shift elements down until */
22 /* insertion point found. */
23 for (j = i-1; j >= lb && compGT(a[j], t); j--)
31 void fill(T *a, tblIndex lb, tblIndex ub) {
34 for (i = lb; i <= ub; i++) a[i] = rand();
37 int main(int argc, char *argv[]) {
38 tblIndex maxnum, lb, ub;
50 maxnum = atoi(argv[1]);
51 lb = 0; ub = maxnum - 1;
52 if ((a = malloc(maxnum * sizeof(T))) == 0) {
53 fprintf (stderr, "insufficient memory (a)\n");
58 insertSort(a, lb, ub);