cxk521aoligei 2021-10-03 17:45 采纳率: 95.2%
浏览 70
已结题

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

希望指出错误

  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      问题事件

      • 系统已结题 10月13日
      • 已采纳回答 10月5日
      • 创建了问题 10月3日

      悬赏问题

      • ¥15 在matlab中如何进行三个参数的离散傅里叶逆变换(idft)
      • ¥15 遇到问题了,求解答!
      • ¥15 请问coppliasim eduUR5视觉抓取怎么实现仿真,
      • ¥30 JavaWeb实验(购物平台)
      • ¥15 八路抢答器倒计时设计时显示器不输出,只能显示0
      • ¥15 用C语言随机生成一个迷宫
      • ¥15 超多因素的正交方案设计
      • ¥15 Scratch~汽车小游戏
      • ¥30 OSGB转换为3dtiles
      • ¥25 用于Audio的芯片中“Audio Interface”和“Mode Control”是什么?