c语言数据结构单链表问题

数据结构与算法分析书上的例题,参考答案后,写的代码还是问题
代码如下

#include<stdio.h>
#include<stdlib.h>
#define LEN sizeof(struct Student)
struct Student
{
    int m;
    struct Student* next;
    
};
struct Student *creatlist();
struct Student *creatlist()
{
    
    int    n,a;
    a=n=0;
    printf("请输入学生人数:");
    scanf("%d",&a);
    struct Student *head,*p1,*p2;
    head=(struct Student*)malloc(LEN);
    printf("请输入数据:"); 
    while(n<a)
    {
        p1=(struct Student*)malloc(LEN);
        scanf("%d",&p1->m);
        n++;
        if(head->next==NULL)
        {
            head->next=p1;
            p2=p1;
        }
        else
        {
            p2->next=p1;
            p2=p1;
            
            
            
            
        }
        p2->next=NULL;
        
        
        
    }
    
    
    
    
    return head;
}
void print(struct Student* L,struct Student* P);
void print(struct Student* L,struct Student* P)
{
 struct Student* t1,*t2;
    t1 = L->next;
    t2 = P->next;
    int poi;
    poi = 1;
    while(t1 != NULL && t2 != NULL)
    {
        if(t2->m == poi++)
        {
            printf("%d\n",t1->m);
            t2 = t2->next;
        }
        t1 = t1->next;
    }
    
    
}

int main()
{
    struct Student *L,*P;
    L=creatlist();
    P=creatlist();
    print(L,P);
    
    
    
    
    return 0;
}


程序运行结果如图

img

希望指出错误

没什么错误,增加了第18行的语句,没看明白 void print(struct Student* L,struct Student* P) 这个函数的作用是输出两个链表的公共部分?,供参考:

#include<stdio.h>
#include<stdlib.h>
#define LEN sizeof(struct Student)
struct Student
{
    int    m;
    struct Student* next;
};
struct Student *creatlist();
struct Student *creatlist()
{
    int    n,a;
    a=n=0;
    printf("请输入学生人数:");
    scanf("%d",&a);
    struct Student *head,*p1,*p2;
    head=(struct Student*)malloc(LEN);
    head->next = NULL;            //修改
    printf("请输入数据:");
    while(n<a)
    {
        p1=(struct Student*)malloc(LEN);
        scanf("%d",&p1->m);
        n++;
        if(head->next == NULL)
        {
            head->next=p1;
            p2=p1;
        }
        else
        {
            p2->next=p1;
            p2=p1;
        }
        p2->next=NULL;
    }
    return head;
}
void print(struct Student* L,struct Student* P);
void print(struct Student* L,struct Student* P)
{
 struct Student* t1,*t2;
    t1 = L->next;
    t2 = P->next;
    int poi;
    poi = 1;
    while(t1 != NULL && t2 != NULL)
    {
        if(t2->m == poi++)
        {
            printf("%d\n",t1->m);
            t2 = t2->next;
        }
        t1 = t1->next;
    }
    
}
int main()
{
    struct Student *L,*P;
    L=creatlist();
    P=creatlist();
    print(L,P);
    
    return 0;
}