/* MEMSORT - memory approach to sorting an array * 1 april 2020 * polprog.net */ #include #include #define N 10 int main(){ int array[] = {1, 6, 3, 7, 7, 2, 9, 4, 5, 0}; int max = 0; int *bp; //base pointer //Find max for(int i = 0; i < N; i++){ max = array[i] > max ? array[i] : max; } bp = calloc(sizeof(int), max); if(!bp){ fprintf(stderr, "Here's a nickel kid, get yourself a real computer\n"); return 1; } for(int i = 0; i < N; i++){ bp[array[i]]++; } for(int i = 0; i < N; i++){ for(int j = 0; j < bp[i]; j++){ printf("%d ", i); } } printf("\n"); free(bp); return 0; }