/*先发一个完整的(尚未调通:sorting死循环)*/
#include<stdio.h>
struct stu
{
int num;
struct stu* next;
};
struct stu *sorting(struct stu *head)
{
struct stu *head1,*p,*p1,*p2,*t;
head1=NULL;
t=head;
while(t!=NULL)
{
p=t;
p1=head1;
if(head1==NULL)
head1=p;
else
{
while((p->num>p1->num)&&(p1->next!=NULL))
{
p2=p1;
p1=p1->next;
}
if(p->num<p1->num)
{
if(head1==p1)
head1=p;
else
p2->next=p;
p->next=p1;
}
else
p1->next=p;
}
t=t->next;
}
return head1;
}
main()
{
struct stu ary[6]={
78,ary+1, 98,ary+2, 68,ary+3,
88,ary+4, 47,ary+5, 99,NULL };
struct stu *head=ary,*p;
p=head;
while(p!=NULL)
{
printf("%d\t",p->num);
p=p->next;
}
printf("\n");
p=sorting(head);
while(p!=NULL)
{
printf("%d\t",p->num);
p=p->next;
}
printf("\n");
}