问题
问答题 简答题
设一个带头结点的单向链表的头指针为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;}
}