1 #include <iostream>
2 //石家庄铁道大学 信1405-1 唐炳辉
3 using namespace std;
4 #define N 10
5
6
7 struct JSPX
8 {
9 int num;
10 JSPX *next;
11 JSPX()
12 {
13 next=NULL;
14 }
15 };
16
17 JSPX *headn,*Numarr,*Di[N],*Ding[N];
18
19 void Nsort(int t)//对各个位进行排序
20 {
21 int i,k=1,r,bn;
22 for(i=1;i<=t;i++)
23 {
24 k*=N;
25 }
26 r=k*N;
27
28 for(i=0;i<N;i++)
29 {
30 Ding[i]=Di[i];
31 }
32 for(Numarr=headn->next;Numarr!=NULL;Numarr=Numarr->next)
33 {
34 bn=(Numarr->num%r)/k;//根据t 的值不同获取不同位置上的数字
35 Ding[bn]->next=Numarr;//把对应的数字插到板上
36 Ding[bn]=Ding[bn]->next;
37 }
38
39
40 Numarr=headn;
41 for(i=0;i<N;i++)//穿插起来
42 {
43 if(Ding[i]!=Di[i])
44 {
45 Numarr->next=Di[i]->next;
46 Numarr=Ding[i];
47 }
48 }
49 Numarr->next=NULL;
50
51
52 }
53
54 void printJSPX()
55 {
56 for(Numarr=headn->next;Numarr!=NULL;Numarr=Numarr->next)
57 {
58 cout<<Numarr->num<<' ';
59 }
60 cout<<endl;
61 }
62
63 int main()
64 {
65 int i,n,z=0,maxn=0;
66 Numarr=headn=new JSPX;
67 cout<<"请输入你要排序的数字的个数";
68 cin>>n;
69 for(i=0;i<N;i++)
70 {
71 Ding[i]=Di[i]=new JSPX;
72 }
73 for(i=1;i<=n;i++)//插入一系列数字
74 {
75 Numarr=Numarr->next=new JSPX;
76 cin>>Numarr->num;
77 maxn=max(maxn,Numarr->num);
78 }
79 while(maxn/N>0)//最大的数
80 {
81 maxn/=N;
82 z++;
83 }
84 for(i=0;i<=z;i++)//最大的数字的位数减一
85 {
86
87 Nsort(i);
88 }
89 printJSPX();
90 return 0;
91 }