设一个带头结点的单向链表的头指针为head,设计算法,将链表的记录,按照data域的值递增排序。
正确答案:voidassending(Lnode*heaD.
{Lnode*p,*q,*r,*s;
p=head->next;q=p->next;p->next=NULL;
while(q)
{r=q;q=q->next;
if(r->data<=p->datA.
{r->next=p;head->next=r;p=r;}
else
{while(!p&&r->data>p->datA.
{s=p;p=p->next;}
r->next=p;s->next=r;}
p=head->next;}
}
{Lnode*p,*q,*r,*s;
p=head->next;q=p->next;p->next=NULL;
while(q)
{r=q;q=q->next;
if(r->data<=p->datA.
{r->next=p;head->next=r;p=r;}
else
{while(!p&&r->data>p->datA.
{s=p;p=p->next;}
r->next=p;s->next=r;}
p=head->next;}
}
答案解析:有
微信扫一扫手机做题