/* This is a simple exchange sort. Adjacent records are compared and if the first is greater than the second, there is an exchange of records in the array. The sorting continues as long as there are exchanges occurring (as indicated by exch). */ typedef int stuff[10001]; void sort (stuff val, int *len) { int j = 1; /* Initialize outer loop index */ int k; int exch; /* Flag indicating an exchange */ int thold; /* Temporary for the exchange */ do { exch = 0; k = 0; while (k < *len - j) { if (val[k] > val[k+1]) { thold = val[k]; /* Make an exchange */ val[k] = val[k+1]; val[k+1] = thold; exch = 1; } k++; /* On to the next one */ } j++; } while (exch); /* If there was an exchange, keep going */ } /* This function counts the number of values not present in an array and returns that number in misct. The array (val) is assumed to be sorted and to contain size numbers in the range 0 to limit-1. Any number between 0 and limit-1 that does not appear is regarded as missing and is counted as part of misct. */ void missing (stuff val, int *size, int *misct, int *limit) { int j=0; /* Initializing some counters */ int which=0; *misct = 0; do { if (val[j] > which) /* When true, represents a missed value to be counted */ { (*misct)++; which++; } else if (val[j] == which) /* True when value first found */ { which++; j++; } else j++; /* True for already found values */ } while ((j < *size) && (which < *limit)); if (which < *limit) /* Adjust for values not reached by the time the end of the array is reached */ *misct = *misct + *limit - which; return; }