#include
#include
#include
typedef struct Number
{
int data;
struct Number *next;
}Number;
void main()
{
Number head;
Number *p,*q,*t;
char input;
int temp,i,howmany=0,j;
printf("Please input the number string:\n");
p=&head;
p->data=NULL;
while((input=getchar())!='0')
{
temp=atoi(&input);
q=(Number *)malloc(sizeof(Number));
q->data=temp;
p->next=q;
p=q;
++howmany;
}
p->next=NULL;
/*开始比较*/
p=head.next;
q=&head;
t=p->next;
for(i=1;i<=howmany;++i)
{
for(j=i+1;j<=howmany;++j)
{
if (p->data<=t->data)
{
q=p;
p=t;
t=t->next;
}
else
{
q->next=t;
if(t->next==NULL)
{
p->next=NULL;
}
else
{
p->next=t->next;
}
t->next=p;
q=p;
p=t;
t=t->next;
}
}
}
/*输出*/
printf("New order number string:\n");
p=head.next;
while(p)
{
printf("%d",p->data);
p=p->next;
if (p)
{
printf("->");
}
}
//getch();
}
这是第一个问题的答案,但是比较那个部分有点问题,对于输入210测试没有问题,你可以改一改