[Home]
[Contents]
[Chapter]
[Previous Algorithm]
[Next Algorithm]


Top-down radix sort


list sort( s, j ) list s; int j; { int i; list head[M], t; struct rec aux; extern list Last; if (s==NULL) return(s); if ( s->next == NULL ) {Last = s; return(s);} if ( j>D ) { for (Last=s; Last->next!=NULL; Last = Last->next); return( s ); } for (i=0; i<M; i++) head[i] = NULL; /*** place records in buckets ***/ while (s != NULL) { i = charac( j, s->k ); t = s; s = s->next; t->next = head[i]; head[i] = t; } /*** sort recursively ***/ t = &aux; for (i=0; i<M; i++) if (head[i]!=NULL) { t->next = sort( head[i], j+1 ); t = Last; } return(aux.next); }

C source (424b.sort.c)



© Addison-Wesley Publishing Co. Inc.