node *sort(node *head)
{
node *head1,*p,*q,*s,*r;
head1=NULL;
p=head;
while(p!=NULL)
{
s=(node*)malloc(sizeof(node));
strcpy(s->data,p->data);
s->n=p->n;
s->next=NULL;
if(head1!=NULL||strcmp(s->data,head1->data)<0)
{
s->next=head1;
head1=s;
}
else
{
q=head1;r=q;
while(r!=NULL&&strcmp(s->data,r->data)>0)
if(strcmp(s->data,r->data)>0)
{
q=r;
r=r->next;
}
if(r==NULL)
{
q->next=s;
}
else
{
s->next=r;
q->next=s;
}
}
p=p->next;
}
return head1;
}
字符串排序
最新推荐文章于 2022-07-27 17:31:06 发布