Please note that the code is insufficient
Reference book: MIN data structure. C language Edition "
RadixSort.cpp: Defines the entry point of the console application. #include "stdafx.h" #define MAX_SIZE 1000//Maximum space # define RADIX 10//keyword cardinality # key_num 3//keyword number struct slnode{// Static linked list node int key;int next;}; struct sllist{//static linked list Slnode base[max_size];int keynum;//keyword number int len;}; typedef int ARRTYPE [radix];//pointer array void initlist (Sllist * list,int * array,int num) {for (int i = 0; i < num; i++) {list-& Gt;base[i].next = i + 1;list->base[i+1].key = array[i];} List->base[num].next = 0;list->len = Num;list->keynum = 3;} int ord (int key,int i) {//Get address (0~9) if (i = = 0) {return key% 10;} else if (i = = 1) {return key% 100/10;} Else{return key/100;}} Allocation function//i: number of keywords//f: Team head pointer array//e: tail pointer array void Distribute (Sllist * list,int i,arrtype * F,arrtype * e) {for (int j = 0; J < RADIX; J + +) (*f) [j] = 0;//Empty team Header data int next = List->base[0].next;for (; next = = 0; next = list->base[next].next) {int index = O RD (List->base[next].key,i), if ((*f) [index] = = 0) {(*f) [index] = next;} else{list->base[(*e) [Index]].next = Next;} (*e) [Index] = next;} printf ("\ n");} int GetNext (Arrtype f,int i) {for (; i < RADIX; i++) {if (f[i]! = 0) {return i;}} return-1;} The collection function (the allocation function already blocks the array that needs to be sorted and now needs to link the blocks) void Collect (Sllist * List,arrtype f,arrtype e) {int first = GetNext (f,0); if (First! =-1) {List->base[0].next = f[first];//sets the successor int of the head pointer next = GetNext (f,first+1); int pre = FIRST;FOR (; next! =-1;) {list->base[e[pre]].next = F[next];p re = Next;next = GetNext (f,next+1);} List->base[e[pre]].next = 0;//Set the successor of the last node to 0}}void printlist (sllist list) {printf ("------------------ Print static list--------------------\ n "), int next = List.base[0].next;while (next! = 0) {Slnode nextnode = List.base[next];p rintf ( "%d\t", nextnode.key); next = Nextnode.next;} printf ("\ n");} void Radixsort (Sllist * list) {Arrtype F; Arrtype e;for (int i = 0; i < list->keynum; i++) {Distribute (list,i,&f,&e);//assignment, time complexity O (n), n is the size of the sorted array collect (list,f,e);//Collect ... printlist (*list);}} static int testarray[] = {656,301,305,998,999,875,832,423,432,565};int _tmain (int argc, _tchar* argv[]) {sllist list;initlist (&list,testarray,10); Radixsort (&list); return 0;}
Run:
Printed 3 static linked lists, respectively, for the "single digit", "10 bits", "hundred" allocation, after the collection of static linked list situation.
Look at the data structure write code (65) Cardinal sort