#include<stdio.h>
#include<stdlib.h>
#include<iostream.h>
#define KEYN 3
struct ele{
int key;
struct ele *link;
};
void bases(ele **h)
{
?? ele *head[10],*tail[10],*p,*u;
?? int factor=1,i,j;
?? p=*h;
?? for(i=0;i<KEYN;i++)
?? {
?? for(j=0;j<10;j++)
?? {head[j]=NULL;
??? tail[j]=NULL;
?? }
?? while(p)
?? {
????? u=p->link;
???????? j=(p->key/factor)%10;
?? if(head[j]==NULL)
??? head[j]=p;
?? else
??? tail[j]->link=p;
?? tail[j]=p;
?? tail[j]->link=NULL;
?? p=u;
?? }
?? p=NULL;
?? for(j=0;j<10;j++)
?? {
????? if(head[j]==NULL)
??? continue;
?? if(p==NULL)
??? p=head[j];
?? else
??? u->link=head[j];
?? u=tail[j];
?? }
? factor*=10;
?? }
??? *h=p;
}
void main()
{
ele *h,*u;
int a[10];
cout<<"輸入10個數:"<<endl;
for(int i=0;i<10;i++)
? cin>>a[i];
h=NULL; /*先形成一個空鏈表*/
for(i=0;i<10;i++)
{ /*任意形成一個鏈表*/
u=new(ele);
u->key=a[i];
u->link=h;
h=u;
}
bases(&h); /*排序*/
for(u=h;u;u=u->link) /*順序輸出鏈表各表元的鏈值*/
cout<<u->key<<' ';
cout<<endl;
}
posted @
2006-05-12 10:32 小歪 閱讀(863) |
評論 (0) |
編輯 收藏
??????? 終于,我有了自己的博客了。鑒于本人水平實在是有限,所以我還是跟著大家一起學習一段時間后,再發表個人意見了。
??????? 恩,我是研究安全算法的,所以,有對算法上的問題(特別是密碼學方面的)可以探討,大家共同進步!
posted @
2006-04-25 18:09 小歪 閱讀(247) |
評論 (3) |
編輯 收藏