基数排序C语言实现

按照严老师P288页算法编写,严老师的程序有个地方有错误,collect里面while(j #include "stdio.h" #include "stdlib.h" typedef int KeysType; #define MAX_NUM_OF_KEY 8 #define RADIX 10 #define MAX_SPACE 100 typedef struct { KeysType keys[MAX_NUM_OF_KEY]; int next; }SLCell; typedef struct { SLCell r[MAX_SPACE]; int keynum; int recnum; }SLList; typedef int ArrType[RADIX]; void CreateSLList(SLList &L) { printf("please input data numbers:/n"); scanf("%d",&L.recnum); printf("please input keynumbers:/n"); scanf("%d",&L.keynum); printf("please input %d numbers:/n",L.recnum); for(int i=1; i<=L.recnum; i++) { for(int j=L.keynum-1; j>=0; j--) scanf("%d",&L.r[i].keys[j]); printf("input next:/n"); } for(i=0; i=0; j--) printf("%d",L.r[i].keys[j]); printf(" "); } printf("/n"); } void Distribute(SLCell (&r)[MAX_SPACE],int i,ArrType &f,ArrType &e) { int j,p; for(j=0; j 输入输出如下:
please input data numbers:
10
please input keynumbers:
3
please input 10 numbers:
2
7
8
input next:
1
0
9
input next:
0
6
3
input next:
9
3
0
input next:
5
8
9
input next:
1
8
4
input next:
5
0
5
input next:
2
6
9
input next:
0
0
8
input next:
0
8
3
input next:
before sort:
278 109 063 930 589 184 505 269 008 083
第1趟收集后:
930 063 083 184 505 278 008 109 589 269
第2趟收集后:
505 008 109 930 063 269 278 083 184 589
第3趟收集后:
008 063 083 109 184 269 278 505 589 930
【基数排序C语言实现】after sort:
008 063 083 109 184 269 278 505 589 930
Press any key to continue

    推荐阅读