1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > c语言几个字符串排序 请教多个字符串排序(不用数组)

c语言几个字符串排序 请教多个字符串排序(不用数组)

时间:2022-07-04 12:38:17

相关推荐

c语言几个字符串排序 请教多个字符串排序(不用数组)

该楼层疑似违规已被系统折叠隐藏此楼查看此楼

#include

#include

structstud{char*pp;intsum;structstud*next;};

structstud*creat1(intn)

{structstud*head,*newer,*p1,*p2;intt=0,k=0;char*pp1;

printf("输入字符串:");

newer=(structstud*)malloc(sizeof(structstud));

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=(structstud*)malloc(sizeof(structstud));

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);

}

voidprint(structstud*head)

{while(head!=0){puts(head->pp);printf("\n");head=head->next;}}

main()

{structstud*p;intx;

printf("输入字符串的数量:\n");

scanf("%d",&x);

p=creat1(x);printf("降序排列字符串:\n");print(p);

system("PAUSE");

}

请教下各位指点迷津...看到链表这里还是有些晕

排序标准字符串各字符的asc2码值和

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。