鱼C论坛

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

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

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

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

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

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

捕获.JPG

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

struct student *creat();
void print(struct student *);
struct student *dele(struct student *, int);
struct student *add(struct student *);

struct student
{
        int num;
        float score;
        struct student *next;
};
int n = 0;

void main()
{
        int m;
        struct student *p = creat();
        printf("\nstudent is num = %d\n\n", n);
        print(p);
        printf("\nplease delete num: ");
        scanf("%d", &m);
        p = dele(p, m);
        printf("\nstudent is num = %d\n\n", n);
        print(p);
        p = add(p);
        printf("student is num = %d\n\n", n);
        print(p);
}

struct student *creat()
{
        struct student *p1, *p2, *head;
        char ch;
        int num = 0;
        p1 = p2 = (struct student *)malloc(LEN);
        printf("please input num: ");
        scanf("%d", &p1->num);

#if 0
        while((ch = getchar()) != '\n')
        {
                if(ch >='0' && ch<='9')
                {
                        num = num * 10 + (ch - '0');
                }
        }
        p1->num = num;
#endif

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

        head = NULL;
        while(p1->num)
        {
                n++;
                if(n == 1)
                {
                        head = p1;
                }
                else
                {
                        p2->next = p1;
                }
                p2 = p1;
                p1 = (struct student *)malloc(LEN);

                printf("\nplease input num: ");
                scanf("%d", &p1->num);
                printf("please input score: ");
                scanf("%f", &p1->score);
        }
        free(p1);
        p2->next = NULL;
        return head;
}

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

struct student *dele(struct student *head, int m)
{
        struct student *p1, *p2;
        if(!head)
        {
                printf("\nThis list is null!\n");
                goto END;
        }
        p1 = head;
        while(p1->num != m && p1->next != NULL)
        {
                p2 = p1;
                p1 = p1->next;
        }
        if(m == p1->num)
        {
                if(p1 == head)
                {
                        head = p1->next;
                }
                else
                {
                        p2->next = p1->next;
                        free(p1);
                }
                printf("\nDelete No: %d succeed!\n", m);
                n--;
        }
        else
        {
                printf("%d not been found!\n", m);
        }
END:
        return head;
}

struct student *add(struct student *p)
{
        struct student *pn, *head = p, *p1;
        pn = (struct student *)malloc(LEN);
        printf("\nplease input add num: ");
        scanf("%d", &pn->num);
        printf("please input add score: ");
        scanf("%f", &pn->score);
        if(!p)
        {
                p = pn;
                pn->next = NULL;
        }
        else
        {
                while(pn->num > p->num && p->next)
                {
                        p1 = p;
                        p = p->next;
                }
                if(pn->num <= p->num)
                {
                        if(head == p)
                        {
                                head = pn;
                        }
                        else
                        {
                                p1->next = pn;
                        }
                        pn->next = p;
                }
                else
                {
                        p->next = pn;
                        pn->next = NULL;
                }
        }
        n++;
        return head;
}
最佳答案
2022-10-19 09:19:36
好像确实没有
十.png

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

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

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

哟找到了b站的第一版的视频,发现59课就是58课
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

现场直播重合事件.........
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-9-20 14:40

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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