该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
#include
struct stud{char *pp; int sum;struct stud *next;};
struct stud *creat1(int n)
{ struct stud *head,*newer, *p1,*p2; int t=0,k=0; char *pp1;
printf("输入字符串:");
newer=(struct stud*)malloc(sizeof(struct stud));
newer->pp=(char*)malloc(sizeof(char)*15);
gets(newer->pp); pp1=newer->pp;
while(*pp1) k+=*pp1++; newer->sum=k;
head=p1=p2=0;
while(t
{ t++;
if(head==0) { head=newer;newer->next=0;p1=head;}
else {while(p1->sum>newer->sum&&p1->next!=0)
{p2=p1;p1=p1->next;}
if(p1->sumsum)
if(head==p1)
{newer->next=p1;newer->next=head;head=newer;}
else {p2->next=newer;newer->next=p1;}
else
{p1->next=newer;newer->next=0;} p1=head;
newer=(struct stud*)malloc(sizeof(struct stud));
newer->pp=(char*)malloc(sizeof(char)*15);
gets(newer->pp); pp1=newer->pp;k=0;
while(*pp1) k+=*pp1++; newer->sum=k; }
newer->next=0;
}
return(head);
}
void print(struct stud *head)
{ while(head!=0) {puts(head->pp);printf("\n");head=head->next;} }
main()
{struct stud *p; int x;
printf("输入字符串的数量:\n");
scanf("%d",&x);
p=creat1(x);printf("降序排列字符串:\n");print(p);
system("PAUSE");
}
请教下各位指点迷津...看到链表这里还是有些晕
排序标准字符串各字符的asc2码值和