读书人

求解 如果这样排序C语言链表排列头

发布时间: 2012-04-27 11:57:44 作者: rapoo

求解 ,如果这样排序,C语言链表排列头指针 怎么参加排序啊?
void order(struct Book *head)
{
struct Book *p,*q,*temp;
for(q=head;q->next!=NULL;q=q->next)
for(p=q->next;p->next!=NULL;p=p->next)//p从q后续开始到p后续为0
if(q->next->num> p->next->num)
{
if(q->next==p)//如果p为q的后续,交换三个指针
{
temp=p->next;
p->next=p->next->next;
temp->next=p;
q->next=temp;
p=temp;
}
else//否则交换4个指针
{
temp=q->next->next;
q->next->next=p->next->next;
p->next->next=temp;
temp=p->next;
p->next=q->next;
q->next=temp;
}
}
}

[解决办法]

探讨
额,不是啊 ,我问的是排序,这么排序只能排列头指针以后的数据,头指针不参加排序。。。怎么该 让头指针参加排序。。。

[解决办法]
探讨
struct Book *Sort(struct Book*head)
{
struct Book *temp_head;
temp_head=head;
temp_head->next=head;
order(temp_head);
return temp_head->next;
}


void order(struct Book *temp_head)
{
struc……

读书人网 >C语言

热点推荐