鱼C论坛

 找回密码
 立即注册
查看: 893|回复: 0

[技术交流] 按自己理解写的链表代码

[复制链接]
发表于 2020-8-17 20:12:36 | 显示全部楼层 |阅读模式

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

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

x
#include<stdio.h>
#include<string.h>
struct student
{
        int num;
        float score;
        struct student* next;
};
#define LEN sizeof(struct student)
struct student* creat();
void scan(struct student* head);
void print(struct student* point);
int main()
{
        struct student* head = (struct student*)malloc(LEN);
        struct student* point = head;
        scan(head);
        print(head);
}

struct student* creat()
{
        struct student* list = (struct student*)malloc(LEN);
        list->num = 0;
        list->score = 0;
        list->next = NULL;
        return list;
}
void scan(struct student* head)
{
        printf("please enter the num:");
        scanf_s("%d", &(head->num));
        printf("please enter the score:");
        scanf_s("%f", &head->score);
        while (head->num)
        {
                head->next = creat();
                head = head->next;

                printf("please enter the num:");
                scanf_s("%d", &head->num);
                printf("please enter the score:");
                scanf_s("%f", &head->score);
        }
}
void print(struct student* point)
{
        while (point->num)
        {
                printf("num:%d\tscore:%.2f\n", point->num, point->score);
                point = point->next;
        }
}









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

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-22 02:28

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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