俩个链表相连出问题了
程序代码:#include <stdio.h>
#include <malloc.h>
struct list
{ int data;
struct list *next;
};
typedef struct list node;
typedef node* link;
link cteat(void) //建链表函数cteat
{link ptr,head;
int i;
ptr=(link)malloc(sizeof(node));
head=ptr;
for(i=0;i<=3;i++)
{ scanf("%d",&ptr->data);
ptr->next=(link)malloc(sizeof(node));
if(i==3)
ptr->next=NULL;
else
ptr=ptr->next;
}
return(head);
}
link insert(link head1,link head2) //连接函数insert
{ link p00,p1,p2,p0;
p1=head1;
p00=head2;
while(p00!=NULL)
{ p0=p00;
while(p0->data>p1->data&&p1!=NULL)
{ p2=p1;
p1=p1->next;
}
if(p0->data<p1->data)
{ if(head1==p1)head1=p0;
else p2->next=p0;
p0->next=p1;
}
else
{ p1->next=p0;
p0->next=NULL;
}
P00=P00->next;/*这里说P00没定义,不知道为什么*/
}
return(head1);
}
int main()
{link head1,head2,head,ptr;
head1=cteat();
head2=cteat();
head=insert(head1,head2);
ptr=head;
while(ptr!=NULL)
{ printf("data==%d\n",ptr->data);
ptr=ptr->next;
}
}我是想假如链表head1和head2.里都是按顺序排列的,把head2插到head1中,插入后也是按小到大的顺序拍可就出现/*这里说P00没定义,不知道为什么*/ 那里要改进的请各位指出。









