字符串排序

来源:互联网 发布:淘宝贝亲奶瓶正品 编辑:程序博客网 时间:2024/06/05 07:04
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;}
0 0
原创粉丝点击