链表排序问题
我想将两个非递减的链表合并成一个非递增的新链表;但是出了点问题,请大家看看;struct Node *MergeLisk(struct Node *head1,struct Node *head2)
{
struct Node *p1;/*链表一中的工作指针*/
struct Node *q1;/*链表二中的工作指针*/
//struct Node *t1;/*链表三中的工作指针*/
struct Node *p2;/*链表一中用来记录p1下一个结点*/
struct Node *q2;/*链表二中用来记录q1的下一个结点*/
struct Node *head3;
head3=head1;
p1=head1->next;
q1=head2->next;
head3->next=NULL;
while(p1!=NULL&&q1!=NULL)
{
if(p1->iNum<=q1->iNum)
{
p2=p1->next ;
p1->next =head3->next ;
head3->next =p1;
p1=p2;
}
else{
q2=q1->next ;
q1->next=head3->next ;
head3->next=q1;
q1=q2;
}
}
if(p1==NULL)/*

{
q2=q1->next;
q1->next=head3->next;
head3->next=q1;
q1=q2;
}
if(q1==NULL)
{
p2=p1->next ;
p1->next=head3->next ;
head3->next=p1;
p1=p2;
}
free(head2);