正文

基数排序2007-09-16 23:37:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/wfxsky/29448.html

分享到:

/* 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;}         

阅读(436) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册