鱼C论坛

 找回密码
 立即注册
查看: 2437|回复: 3

[已解决]第58节课件是不是没有啊?

[复制链接]
发表于 2022-10-18 22:14:48 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
RT,第58课离奇失踪了 是没有么还是我下载的课件不全啊

捕获.JPG

附上链表作业
  1. #include<stdio.h>
  2. #include<malloc.h>
  3. #define LEN sizeof(struct student)

  4. struct student *creat();
  5. void print(struct student *);
  6. struct student *dele(struct student *, int);
  7. struct student *add(struct student *);

  8. struct student
  9. {
  10.         int num;
  11.         float score;
  12.         struct student *next;
  13. };
  14. int n = 0;

  15. void main()
  16. {
  17.         int m;
  18.         struct student *p = creat();
  19.         printf("\nstudent is num = %d\n\n", n);
  20.         print(p);
  21.         printf("\nplease delete num: ");
  22.         scanf("%d", &m);
  23.         p = dele(p, m);
  24.         printf("\nstudent is num = %d\n\n", n);
  25.         print(p);
  26.         p = add(p);
  27.         printf("student is num = %d\n\n", n);
  28.         print(p);
  29. }

  30. struct student *creat()
  31. {
  32.         struct student *p1, *p2, *head;
  33.         char ch;
  34.         int num = 0;
  35.         p1 = p2 = (struct student *)malloc(LEN);
  36.         printf("please input num: ");
  37.         scanf("%d", &p1->num);

  38. #if 0
  39.         while((ch = getchar()) != '\n')
  40.         {
  41.                 if(ch >='0' && ch<='9')
  42.                 {
  43.                         num = num * 10 + (ch - '0');
  44.                 }
  45.         }
  46.         p1->num = num;
  47. #endif

  48.         printf("please input score: ");
  49.         scanf("%f", &p1->score);

  50.         head = NULL;
  51.         while(p1->num)
  52.         {
  53.                 n++;
  54.                 if(n == 1)
  55.                 {
  56.                         head = p1;
  57.                 }
  58.                 else
  59.                 {
  60.                         p2->next = p1;
  61.                 }
  62.                 p2 = p1;
  63.                 p1 = (struct student *)malloc(LEN);

  64.                 printf("\nplease input num: ");
  65.                 scanf("%d", &p1->num);
  66.                 printf("please input score: ");
  67.                 scanf("%f", &p1->score);
  68.         }
  69.         free(p1);
  70.         p2->next = NULL;
  71.         return head;
  72. }

  73. void print(struct student *p)
  74. {
  75.         do
  76.         {
  77.                 printf("\ttnum = %d\t\tscore = %.2f\n", p->num, p->score);
  78.                 p = p->next;
  79.         }while(p);
  80. }

  81. struct student *dele(struct student *head, int m)
  82. {
  83.         struct student *p1, *p2;
  84.         if(!head)
  85.         {
  86.                 printf("\nThis list is null!\n");
  87.                 goto END;
  88.         }
  89.         p1 = head;
  90.         while(p1->num != m && p1->next != NULL)
  91.         {
  92.                 p2 = p1;
  93.                 p1 = p1->next;
  94.         }
  95.         if(m == p1->num)
  96.         {
  97.                 if(p1 == head)
  98.                 {
  99.                         head = p1->next;
  100.                 }
  101.                 else
  102.                 {
  103.                         p2->next = p1->next;
  104.                         free(p1);
  105.                 }
  106.                 printf("\nDelete No: %d succeed!\n", m);
  107.                 n--;
  108.         }
  109.         else
  110.         {
  111.                 printf("%d not been found!\n", m);
  112.         }
  113. END:
  114.         return head;
  115. }

  116. struct student *add(struct student *p)
  117. {
  118.         struct student *pn, *head = p, *p1;
  119.         pn = (struct student *)malloc(LEN);
  120.         printf("\nplease input add num: ");
  121.         scanf("%d", &pn->num);
  122.         printf("please input add score: ");
  123.         scanf("%f", &pn->score);
  124.         if(!p)
  125.         {
  126.                 p = pn;
  127.                 pn->next = NULL;
  128.         }
  129.         else
  130.         {
  131.                 while(pn->num > p->num && p->next)
  132.                 {
  133.                         p1 = p;
  134.                         p = p->next;
  135.                 }
  136.                 if(pn->num <= p->num)
  137.                 {
  138.                         if(head == p)
  139.                         {
  140.                                 head = pn;
  141.                         }
  142.                         else
  143.                         {
  144.                                 p1->next = pn;
  145.                         }
  146.                         pn->next = p;
  147.                 }
  148.                 else
  149.                 {
  150.                         p->next = pn;
  151.                         pn->next = NULL;
  152.                 }
  153.         }
  154.         n++;
  155.         return head;
  156. }
复制代码
最佳答案
2022-10-19 09:19:36
好像确实没有
十.png

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2022-10-19 09:19:36 | 显示全部楼层    本楼为最佳答案   
好像确实没有
十.png

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-10-19 10:50:49 From FishC Mobile | 显示全部楼层
高山 发表于 2022-10-19 09:19
好像确实没有

哟找到了b站的第一版的视频,发现59课就是58课
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-10-19 15:31:30 | 显示全部楼层
竹逸 发表于 2022-10-19 10:50
哟找到了b站的第一版的视频,发现59课就是58课

现场直播重合事件.........
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-16 09:58

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表