带表头结点的链表 程序错误 运行不出来 帮忙看看

来源:百度知道 编辑:UC知道 时间:2024/06/02 16:58:20
两个递增数列 合并
#include <stdio.h>
#define NULL 0
struct student
{long num;
int score;
struct student *next;
};

int n,sum=0;

main()
{struct student *creat(void);
struct student *insert(struct student *ah,struct student *bh);
void print(struct student *h);
struct student *ah,*bh,*abh;
printf("input list a\n");
ah=creat();
sum=sum+n;
printf("input list b\n");
bh=creat();
sum=sum+n;
abh=insert(ah,bh);
print(abh);
}

struct student *creat(void)
{struct student *p1,*p2,*head;
n=0;
head=(struct student *) malloc(sizeof(struct student));
head->next=NULL;
p2=head->next;
printf("input\n");
p1=(struct student *) malloc(sizeof(struct student));
scanf("%ld,%d",&p1->num,&p1->score);
while(p1->num!=0)
{n=n+1;
p2->next=

struct student *creat(void)
{struct student *p1,*p2,*head;
n=0;
head=(struct student *) malloc(sizeof(struct student));
head->next=NULL;
p2=head->next;//此行错误了吧改为p2=head;
printf("input\n");
p1=(struct student *) malloc(sizeof(struct student));
scanf("%ld,%d",&p1->num,&p1->score);
while(p1->num!=0)
{n=n+1;
p2->next=p1;p2=p1;
p1=(struct student *) malloc(sizeof(struct student));
scanf("%ld,%d",&p1->num,&p1->score);

}

合并:
Node * MergeRecursive(Node *head1 , Node *head2)
{
if ( head1 == NULL )
return head2 ;
if ( head2 == NULL)
return head1 ;
Node *head = NULL ;
if ( head1->data < head2->data )
{
head = head1 ;
head->next = MergeRecursive(head1->next,head2);
}
else
{
head = head2 ;
head->next = MergeRecursive(head1,head2->next);
}
return hea