编辑代码

#include <stdio.h>
#include <malloc.h>
#include <string.h>
struct student {
    int num;
    struct student * next;
};
int n=0,sum=0;
int main () {
    struct student * creat();
    struct student * cp(struct student *,struct student *);
    struct student *ah,*bh;
    void print(struct student *);
    ah=creat();
    print(ah);
    sum=sum+n;
    bh=creat();
    print(bh);
    sum=sum+n;
    ah=cp(ah,bh);
    print(ah);
	return 0;
}
struct student * creat(){
    struct student *p1,*p2,*head;
    n=0;
    p1=p2=(struct student *)malloc(sizeof(struct student));
    printf("input number & score of studnet:");
    scanf("%d",&p1->num);
    head=NULL;
    while(p1->num!=0){
        n=n+1;
        if(n==1){
            head=p1;
        }
        else{
            p2->next=p1;
        }
        p2=p1;
        p1=(struct student *)malloc(sizeof(struct student));
        printf("input number & score of student:");
        scanf("%d",&p1->num);
    }
    p2->next=NULL;
    return head;
}
void print(struct student * head){
    struct student *p;
    p=head;
    printf("There are %d records:\n",n);
    do{
        printf("%d\n",p->num);
        p=p->next;
    }while(p!=NULL);
}
struct student *cp(struct student * ah,struct student * bh){
    struct student *pa1,*pa2,*pb1,*pb2;
    pa1=pa2=ah;
    pb1=pb2=bh;
    while(pa1!=NULL&&pb1!=NULL){
    printf("a\n");
        while((pa1->num<=pb1->num)&&(pa1!=NULL)){
            printf("b\n");
            pa2=pa1;
            pa1=pa1->next;
        }
        if(pa1->num>pb1->num){
            printf("c\n");
            if(pa1==ah){
                ah=pb1;
            }else{
                pa2->next=pb1;
            }
            pb1=pb1->next;
            pb2->next=pa1;
            pa2=pb2;
            pb2=pb1;
        }
    }
    if((pa1==NULL)&&(pb1!=NULL)){
        pa2->next=pb1;
    }

    return ah;
}