Hi everyone,
I'm having trouble implementing a supposedly simple Least Significant Digit first Radix Sort. The book I'm using gave me somewhat of a template that I touched up (below), but I'm very unsure of where to start. I know the basic layout (Initialization of memory space, Distribution of numbers in bins, and then Collection of the bins), but I don't know how to code it. The examples I've seen don't pertain to my situation enough to help me. Any help is greatly appreciated.
Thanks,
James
Code:#include <stdio.h> #include <malloc.h> #include <stdlib.h> void lsd_radix_sort(unsigned int *, int); main(int argc, char *argv[]) { int i, nvals = 10000; unsigned int *array; if(argc > 1) nvals = atoi(argv[1]); array = malloc(nvals * sizeof(unsigned int)); for(i = 0; i < nvals; i++) array[i] = rand(); lsd_radix_sort(array, nvals); } #define BITS 8 #define RADIX (1<<BITS) #define DIGITS (32/BITS) void lsd_radix_sort(unsigned int *array, int n) { int i, j, k, d, shift; int *bin[RADIX], n_in_bin[RADIX], size_bin[RADIX]; unsigned int v; /**insertion of least significant digit first code below ****/ }



LinkBack URL
About LinkBacks


