为了账号安全,请及时绑定邮箱和手机立即绑定

作业社区

探索学习新天地,共享知识资源!

0 提交作业
0 布置作业
0 满分作业
得分 100
学习任务

慕尼黑0001808 的学生作业:

//写出下列类型的判空,删除 #ifndef __LIST_H__ #define __LIST_H__ #include #include #include #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; extern seqlist_t *create_empty_seqlist(); extern void printf_data_seqlist(seqlist_t * l); extern int is_empty_seqlist(seqlist_t *l); extern int delete_data_seqlist(seqlist_t *l,datatype_t data); #endif // list.c #include "list.h" //创建空的顺序表 seqlist_t *create_empty_seqlist() { seqlist_t * l = (seqlist_t *)malloc(sizeof(seqlist_t)); if (NULL == l) { printf("malloc seqlist_t fail \n"); return NULL; } return l; } // 打印数据 void printf_data_seqlist(seqlist_t * l) { printf("id\tname\tage\n"); for(int i = 0;in;i++) { printf("%d\t%s\t%d\n",l->buf[i].id,l->buf[i].name,l->buf[i].age); } printf("\n"); } //判断顺序表是否为空 int is_empty_seqlist(seqlist_t *l) { return l->n==0?1:0; } //删除顺序表中指定的数据 int delete_data_seqlist(seqlist_t *l,datatype_t data) { int i = 0,j = 0; if(is_empty_seqlist(l)) { return -1; } for(;in;i++) { // 如果当前元素与要删除的元素不匹配,则保留它 if(!(strcmp(l->buf[i].name,data.name)==0&&l->buf[i].id==data.id&&l->buf[i].age==data.age)) { l->buf[j++] = l->buf[i]; } // 如果匹配(是要删除的元素),则跳过它,不增加j } // 检查是否删除了元素 if(i==j) { // 没有找到要删除的元素 return -2; } l->n = j; return 0; } // main.c #include "list.h" int main() { seqlist_t * l = create_empty_seqlist(); datatype_t data[10] = { {"Alice", 1001, 18}, {"Bob", 1002, 19}, {"Charlie", 1003, 20}, {"David", 1004, 21}, {"Eve", 1005, 19}, {"Frank", 1006, 22}, {"Grace", 1007, 20}, {"Helen", 1008, 23}, {"Ivy", 1009, 21}, {"Jack", 1010, 20} }; memcpy(l->buf,data,sizeof(data)); l->n = 10; printf("删除前:\n"); printf_data_seqlist(l); int result = delete_data_seqlist(l,data[1]); // 删除 Bob printf("删除结果: %d\n", result); printf("删除后:\n"); printf_data_seqlist(l); free(l); l = NULL; return 0; }

得分 100
学习任务

慕尼黑0001808 的学生作业:

#ifndef __LIST_H__ #define __LIST_H__ // list.h //写出下列类型的创建,判满,插入输出 #include #include #include #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(); int is_full_seqlist(seqlist_t *l); void insert_data_seqlist(seqlist_t *l,datatype_t data); void printf_data_seqlist(seqlist_t *l); #endif // list.c #include "list.h" //创建空的顺序表 seqlist_t *create_empty_seqlist() { seqlist_t * l = (seqlist_t *)malloc(sizeof(seqlist_t)); if (NULL == l) { printf("malloc seqlist_t fail \n"); return NULL; } return l; } // 判断顺序表是否已满 int is_full_seqlist(seqlist_t * l) { return l->n == MAX ? 1 : 0; } // 插入数据 void insert_data_seqlist(seqlist_t *l,datatype_t data) { l->buf[l->n] = data; l->n++; } void printf_data_seqlist(seqlist_t * l) { printf("id\tname\tage\n"); for(int i = 0;ibuf[i].id,l->buf[i].name,l->buf[i].age); } printf("\n"); } // main.c #include "list.h" int main() { seqlist_t * l = create_empty_seqlist(); datatype_t data; while(is_full_seqlist(l)==0) { printf("please %d data[name id age]:",MAX); scanf("%s%d%d",data.name,&data.id,&data.age); insert_data_seqlist(l,data); } printf_data_seqlist(l); free(l); l = NULL; return 0; }

得分 100
学习任务

weixin_慕九州3042664 的学生作业:

ubuntu@VM-16-9-ubuntu:~$ sudo apt-get install btanks Reading package lists… Done Building dependency tree Reading state information… Done The following packages were automatically installed and are no longer required: libpcre16-3 libpcre32-3 libpcrecpp0v5 Use ‘sudo apt autoremove’ to remove them. The following additional packages will be installed: btanks-data liblua5.1-0 libsdl-image1.2 libsmpeg0 libvorbisfile3 The following NEW packages will be installed: btanks btanks-data liblua5.1-0 libsdl-image1.2 libsmpeg0 libvorbisfile3 0 upgraded, 6 newly installed, 0 to remove and 76 not upgraded. Need to get 28.6 MB of archives. After this operation, 37.2 MB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://mirrors.tencentyun.com/ubuntu bionic/universe amd64 liblua5.1-0 amd64 5.1.5-8.1build2 [100 kB] Get:2 http://mirrors.tencentyun.com/ubuntu bionic-security/universe amd64 libsdl-image1.2 amd64 1.2.12-8ubuntu0.1 [30.3 kB] Get:3 http://mirrors.tencentyun.com/ubuntu bionic/universe amd64 libsmpeg0 amd64 0.4.5+cvs20030824-7.2 [80.0 kB] Get:4 http://mirrors.tencentyun.com/ubuntu bionic/main amd64 libvorbisfile3 amd64 1.3.5-4.2 [16.0 kB] Get:5 http://mirrors.tencentyun.com/ubuntu bionic/universe amd64 btanks-data all 0.9.8083-7 [26.4 MB] Get:6 http://mirrors.tencentyun.com/ubuntu bionic/universe amd64 btanks amd64 0.9.8083-7 [2,018 kB] Fetched 28.6 MB in 3s (10.9 MB/s) Selecting previously unselected package liblua5.1-0:amd64. (Reading database … 107446 files and directories currently installed.) Preparing to unpack …/0-liblua5.1-0_5.1.5-8.1build2_amd64.deb … Unpacking liblua5.1-0:amd64 (5.1.5-8.1build2) … Selecting previously unselected package libsdl-image1.2:amd64. Preparing to unpack …/1-libsdl-image1.2_1.2.12-8ubuntu0.1_amd64.deb … Unpacking libsdl-image1.2:amd64 (1.2.12-8ubuntu0.1) … Selecting previously unselected package libsmpeg0:amd64. Preparing to unpack …/2-libsmpeg0_0.4.5+cvs20030824-7.2_amd64.deb … Unpacking libsmpeg0:amd64 (0.4.5+cvs20030824-7.2) … Selecting previously unselected package libvorbisfile3:amd64. Preparing to unpack …/3-libvorbisfile3_1.3.5-4.2_amd64.deb … Unpacking libvorbisfile3:amd64 (1.3.5-4.2) … Selecting previously unselected package btanks-data. Preparing to unpack …/4-btanks-data_0.9.8083-7_all.deb … Unpacking btanks-data (0.9.8083-7) … Selecting previously unselected package btanks. Preparing to unpack …/5-btanks_0.9.8083-7_amd64.deb … Unpacking btanks (0.9.8083-7) … Setting up libvorbisfile3:amd64 (1.3.5-4.2) … Setting up btanks-data (0.9.8083-7) … Setting up libsmpeg0:amd64 (0.4.5+cvs20030824-7.2) … Setting up liblua5.1-0:amd64 (5.1.5-8.1build2) … Setting up libsdl-image1.2:amd64 (1.2.12-8ubuntu0.1) … Setting up btanks (0.9.8083-7) … Processing triggers for man-db (2.8.3-2ubuntu0.1) … Processing triggers for mime-support (3.60ubuntu1) … Processing triggers for libc-bin (2.27-3ubuntu1.6) …

微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号