小菜~~~~~~求助!!
各位高手能不能帮我看一下这个程序错在哪了?#include <stdio.h>
#include <malloc.h>
#define NULL 0
#define LEN sizeof(struct list)
struct list
{
int num;
struct list *next;
};
int m,n;
struct list *creat1(void)
{
struct list *head,*p1,*p2;
n=0;
p1=p2=(struct list *)malloc(LEN);
printf("please input the data1:");
scanf("%ld",&p1->num);
head=NULL;
while(p1->num!=0)
{
n++;
if(n==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(struct list *) malloc(LEN);
scanf("%ld",&p1->num);
}
p2->next=NULL;
return(head);
}
struct list *creat2(void)
{
struct list *head,*p1,*p2;
m=0;
p1=p2=(struct list *)malloc(LEN);
printf("please input the data1:");
scanf("%ld",&p1->num);
head=NULL;
while(p1->num!=0)
{
m++;
if(n==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(struct list *) malloc(LEN);
scanf("%ld",&p1->num);
}
p2->next=NULL;
return(head);
}
void print(struct list *head)
{struct list *p;
p=head;
do
{
printf("%ld",p->num);
p=p->next;
}while(p->next!=NULL);
printf("%3d",p->num);
getchar();
}
struct list *toghter(struct list *head1,struct list *head2)
{
struct list *p1,*p2,*p3,*p4,*head;
p1=head1;
p2=head2;
head=head1;
while(p1->next!=NULL&&p2->next!=NULL)
{
p3=p1->next;
p4=p2->next;
p1->next=p2;
p2->next=p3;
p1=p3;
p2=p4;
}
if(p1->next==NULL&&p2->next==NULL)
p1->next=p2;
if(p1->next==NULL&&p2->next!=NULL)
p1->next=p2;
if(p2->next==NULL&&p1->next!=NULL)
{
p3=p1->next;p1->next=p2;p2->next=p3;
}
return(head);
}
void chain(struct list *head)
{struct list *tmp,*btmp;
int i,min;
for(i=0;i<n+m-1;i++)
{
tmp=head;
min=tmp->num;
btmp=NULL;
while(tmp->next)
{
if(min>tmp->next->num)
{
min=tmp->next->num;
btmp=tmp;
}
tmp=tmp->next;
}
printf("%d ",min);
}
}
void main()
{
struct list *head1,*head2,*head;
head1=creat1();
head2=creat2();
print(head1);
print(head2);
head=toghter(head1,head2);
chain(head);
}