/* This is the radxsort */
#include<iostream>
#include<cstdlib>
using namespace std;
const int N=5;
const int K=3;
struct Radx{
int key[N];
int keyNum;
}l[10];
void radxSort(int array[])
{
int i,j,p,q,a;
for(j=1;j<=K;j++)
{
for(p=0;p<10;p++)
{ for(q=0;q<N;q++)
l[p].key[q]=0;
l[p].keyNum=0;
}
for(p=0;p<N;p++)
{
q=j;
a=array[p];
while(q!=0)
{
i=a%10;
a=a/10;
q--;
}
l[i].key[l[i].keyNum]=array[p];
l[i].keyNum++;
}
q=0;
for(i=0;i<10;i++)
for(p=0;p<l[i].keyNum;p++)
{array[q]=l[i].key[p];
q++;}
}
}
int main(void)
{
int array[N]={577,499,889, 966,387};
radxSort(array);
for(int i=0;i<N;i++)
cout <<" "<<array[i];
system("pause");
return 0;
}
评论