【备战春招】第12天 嵌入式工程师学习笔记
课程信息
- 课程名称:物联网/嵌入式工程师
- 章节名称:第5周之第一讲 1-6&7 顺序表的创建、判满、输入、输出
- 讲师姓名:大白老师
课程内容概述
1. 简介
本节介绍了C语言中的顺序表的创建、判满、输入、输出。
2. 存储图形示例
3. 代码示例
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 10
// 实际学⽣的存储
struct student
{
char name[20];
int id;
int age;
};
typedef struct student datatype_t;
typedef struct
{
datatype_t buf[MAX]; // 定义数组记录班级学⽣每个学⽣的信息。
int n; // 学⽣实际到来的个数。
} seqlist_t;
seqlist_t *create_empty_seqlist()
{
seqlist_t *t = NULL;
t = (seqlist_t *)malloc(sizeof(seqlist_t));
if (NULL == t)
{
printf("malloc fail!");
return NULL;
}
memset(t, 0, sizeof(seqlist_t));
return t;
}
int is_full_seqlist(seqlist_t *l)
{
return l->n < MAX ? 0 : 1;
}
void insert_data_seqlist(seqlist_t *l, datatype_t data)
{
l->buf[l->n++] = data;
}
void printf_data_seqlist(seqlist_t *l)
{
printf("NAME\tID\tAGE\t\n");
for (int i = 0; i < l->n; i++)
{
datatype_t t = l->buf[i];
printf("%s%d%d\n", t.name, t.id, t.age);
}
}
int main()
{
seqlist_t *st = NULL;
st = create_empty_seqlist();
while (is_full_seqlist(st) != 1)
{
printf("please input student info\n");
datatype_t t;
scanf("%s%d%d", &t.name, &t.id, &t.age);
insert_data_seqlist(st, t);
}
printf_data_seqlist(st);
return 0;
}
运行结果
please input student info
20 20 20
please input student info
20 20 20
please input student info
20
20 20
please input student info
20
21 2
please input student info
21 22 23
please input student info
22 23 24
please input student info
25 26 23
please input student info
25 25 25
please input student info
45 58 69
please input student info
45 5 2
NAME ID AGE
202020
202020
202020
20212
212223
222324
252623
252525
455869
4552
学习心得
C语言中的数据结构,实践练习了顺序表的创建、判满、输入、输出,感觉很有收获。
课程截图
1. 示例
點擊查看更多內(nèi)容
為 TA 點贊
評論
評論
共同學習,寫下你的評論
評論加載中...
作者其他優(yōu)質文章
正在加載中
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦