Logo Search packages:      
Sourcecode: yorick-imutil version File versions  Download package

insort.c

/*
 *  A library of sorting functions
 *
 *  Written by:  Ariel Faigon,  1987
 */
#include    <stdio.h>
#include    "sort.h"

/*------------------------------------------------------------------- 
 *            This file shouldn't be touched.
 *         For customizable parameters, see 'sort.h'
 *-----------------------------------------------------------------*/

/*
 |  void  insort (array, len)
 |  KEY_T  array[];
 |  int    len;
 |
 |  Abstract:     Sort array[0..len-1] into increasing order.
 |
 |  Method: Optimized insertion-sort (ala Jon Bentley)
 */

void  insort_long (long *array, int len)
{
      int   i, j;
      long  temp;

      for (i = 1; i < len; i++) {
            /* invariant:  array[0..i-1] is sorted */
            j = i;
            /* customization bug: SWAP is not used here */
            temp = array[j];
            while (j > 0 && GT(array[j-1], temp)) {
                  array[j] = array[j-1];
                  j--;
            }
            array[j] = temp;
      }
}

void  insort_float (array, len)
register float  array[];
register int    len;
{
      register int      i, j;
      register float    temp;

      for (i = 1; i < len; i++) {
            /* invariant:  array[0..i-1] is sorted */
            j = i;
            /* customization bug: SWAP is not used here */
            temp = array[j];
            while (j > 0 && GT(array[j-1], temp)) {
                  array[j] = array[j-1];
                  j--;
            }
            array[j] = temp;
      }
}

void  insort_double (array, len)
register double array[];
register int    len;
{
      register int      i, j;
      register double   temp;

      for (i = 1; i < len; i++) {
            /* invariant:  array[0..i-1] is sorted */
            j = i;
            /* customization bug: SWAP is not used here */
            temp = array[j];
            while (j > 0 && GT(array[j-1], temp)) {
                  array[j] = array[j-1];
                  j--;
            }
            array[j] = temp;
      }
}

void  insort_short (array, len)
register short  array[];
register int    len;
{
      register int      i, j;
      register short    temp;

      for (i = 1; i < len; i++) {
            /* invariant:  array[0..i-1] is sorted */
            j = i;
            /* customization bug: SWAP is not used here */
            temp = array[j];
            while (j > 0 && GT(array[j-1], temp)) {
                  array[j] = array[j-1];
                  j--;
            }
            array[j] = temp;
      }
}


Generated by  Doxygen 1.6.0   Back to index