6-3 链表的基本操作-删除链表中的一个结点 分数 10 全屏浏览 切换布局 作者 李志聪 单位 哈尔滨师范大学 有一链式结构,定义如下 : struct stu{ char name[20]; int no; struct stu *next; }; 创建一个函数mydel(p,name),删除链表中name域为name的结点,返回链表的头指针。如果中p链表中结点的name域与name相同,删除结点,并返回头指针,如果没找到,在函数中显示没有找到,返回头指针。 程序中create函数已经为我们创建了一个有10个结点 的无头结点的链表。 函数接口定义: 在这里描述函数接口。例如: struct stu * mydel(struct stu *head,char *name); 在这里解释接口参数。例如:其中 head 和 name 都是用户传入的参数。 head 是已经创建好的无头结点的链表的头指针; name 是最大为19个字符的字符串。 裁判测试程序样例: 在这里给出函数被调用进行测试的例子。例如: #include <stdio.h> #include
```c struct stu * mydel(struct stu *head,char *name) { struct stu *current = head; struct stu *previous = NULL; while (current != NULL) { if (strcmp(current->name, name) == 0) { if (previous == NULL) { head = current->next; } else { previous->next = current->next; } free(current); return head; } previous = current; current = current->next; } printf("no found\n"); return head; } ``` [2025-12-25 15:51:01 | AI问答 | 143点数解答]
相关提问
- [字节豆包] #include <stdio.h> int i; struct stu { char num; char name; int grade[3] }; void input(struct stu stu) { scanf("%s%s", &stu.num, &stu.name); for (int i = 0; i < 3; i++) { scanf("%d", &stu.grade); } } void print(struct stu stu) { printf("%s,%s,", stu.num, stu.name); for (i = 0; i < 2; i++) { printf("%d,", a.grade[i]); }printf("%d\n",stu.grade[2]); } int main() { int n; struct stu a; scanf("%d", &n); for ( i = 0; i < n; i++) { input(a); } for (i = 0; i < n; i++) { print((371点数解答 | 2025-01-03 23:31:22)195
- [字节豆包] 6-3 链表的基本操作-删除链表中的一个结点 分数 10 全屏浏览 切换布局 作者 李志聪 单位 哈尔滨师范大学 有一链式结构,定义如下 : struct stu{ char name[20]; int no; struct stu *next; }; 创建一个函数mydel(p,name),删除链表中name域为name的结点,返回链表的头指针。如果中p链表中结点的name域与name相同,删除结点,并返回头指针,如果没找到,在函数中显示没有找到,返回头指针。 程序中create函数已经为我们创建了一个有10个结点 的无头结点的链表。 函数接口定义: 在这里描述函数接口。例如: struct stu * mydel(struct stu *head,char *name); 在这里解释接口参数。例如:其中 head 和 name 都是用户传入的参数。 head 是已经创建好的无头结点的链表的头指针; name 是最大为19个字符的字符串。 裁判测试程序样例: 在这里给出函数被调用进行测试的例子。例如: #include <stdio.h> #include(143点数解答 | 2025-12-25 15:51:01)36
- [字节豆包] #include<stdio.h> #include<stdlib.h> #include<time.h> int producerand(int remainder); void initprocess(); void chosedisplace(); struct linknode* fifo(struct linknode* head, int randcount); void optimal(struct linknode* head, int randprocess); struct linknode* lru(struct linknode* head, int randprocess); struct linknode* initlink(); void choicestey(); int allotment(struct linknode* head); int checkfifooptimal(struct linknode* head, int checkpage); void recover(struct linknode* head, int randproc(60点数解答 | 2024-12-13 20:02:21)280
- [阿里通义] #include<stdio.h> #include<stdlib.h> #include<time.h> int producerand(int remainder); void initprocess(); void chosedisplace(); struct linknode* fifo(struct linknode* head, int randcount); void optimal(struct linknode* head, int randprocess); struct linknode* lru(struct linknode* head, int randprocess); struct linknode* initlink(); void choicestey(); int allotment(struct linknode* head); int checkfifooptimal(struct linknode* head, int checkpage); void recover(struct linknode* head, int randproc(858点数解答 | 2024-12-13 20:03:47)308
- [字节豆包] c语言现在想将学生绩点组成一个链表。链表结点内容包括学生姓名,学号,绩点。 输入是一组学生的姓名、学号和绩点,以链表形式存储,结点顺序即学生信息的输入顺序。 请在原链接中删除绩点小于平均绩点的学生结点,然后按照输入的顺序,依序输出新链表的学生信息。 平均绩点是输入的所有学生绩点取算术平均值。 1.本题中,头文件已经添加,且学生结点和头结点定义如下: #include<stdio.h> #include<stdbool.h> #include<stdlib.h> #include<string.h> // 学生结点定义 typedef struct student { char name[20];//姓名 char no[20];//学号 float grade;//绩点 struct student *next; } stu; // 头结点定义 typedef struct { int n; //学生个数 float sum;//学生绩点和 float avg;//平均绩点 stu *first; } he(604点数解答 | 2024-12-03 11:10:47)273
- [字节豆包] 7-1 单向链表的创建与输出 分数 100 作者 王群芳 单位 合肥师范学院 本题目要求补充两个函数,实现如下功能: 输入若干个正整数,以-1结束,采取向链表中添加节点的方式来建立一个单链表,并输出这个单链表。 向链表尾部添加节点函数: Link AppendNode(Link head,int data); 其中Link结构定义如下: typedef struct link { int data; struct link *next; }*Link; head:链表头指针,如果head为NULL,则会新建头节点 data:要添加的节点数据值 函数返回值:添加节点后的链表头指针 输出链表函数: void DisplyNode(Link head); head :链表头指针 主函数样例: #include <stdio.h> #include <stdlib.h> typedef struct link { int data; struct link *next; }*Link; Link AppendNode(Link head,int d(351点数解答 | 2025-12-19 20:53:08)30
- [字节豆包] 7-1 单向链表的创建与输出 分数 100 作者 王群芳 单位 合肥师范学院 本题目要求补充两个函数,实现如下功能: 输入若干个正整数,以-1结束,采取向链表中添加节点的方式来建立一个单链表,并输出这个单链表。 向链表尾部添加节点函数: Link AppendNode(Link head,int data); 其中Link结构定义如下: typedef struct link { int data; struct link *next; }*Link; head:链表头指针,如果head为NULL,则会新建头节点 data:要添加的节点数据值 函数返回值:添加节点后的链表头指针 输出链表函数: void DisplyNode(Link head); head :链表头指针 主函数样例: #include <stdio.h> #include <stdlib.h> typedef struct link { int data; struct link *next; }*Link; Link AppendNode(Link head,int d(354点数解答 | 2025-12-19 22:00:13)52
- [字节豆包] #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct sqlist //单链表结构体 { int data; struct sqlist *next; //指针域 }sqlist; void initlist (sqlist *l, sqlist *m, sqlist *n, sqlist *h) { //todo list yes l->next = null; m->next = null; n->next = null; h->next = null; } void emp(sqlist *l) { if (l->next==null) //todo list)yes printf("链表为空表。\n"); else printf("链表为非空表。\n"); } void length(sqlist *l) { sqlist *p; int length = 0; p=l->next; while(p!=null) { length++; p=p->next; } //todo list(345点数解答 | 2024-10-23 23:11:22)246
- [字节豆包] 6-2 有结构文件的读写1 分数 10 作者 龚雄兴 单位 湖北文理学院 学生类型:ST的类型定义如下: typedef struct student{ char name[10],id[10]; int gender; int age; double scored; } ST; 编写函数,从指定的文件上读入若干字符串,每行字符串是一个学生的信息(姓名,学号,性别,年龄,分数)的字符串表示,数据间以空格分隔,将学生们的信息存储于一个结构体中,并利用output()函数输出到指定文件中。 函数接口定义: void fun(FILE *fin,FILE *fout); 其中 fin 和 fout 都是用户传入的参数。 前者是已正常打开的可读文件,而后者是已正常打开的可写文件。 裁判测试程序样例: 在这里给出函数被调用进行测试的例子。例如: #include <stdio.h> #include <stdlib.h> typedef struct student{ char name[10],id[10]; int gender; int age; do(211点数解答 | 2025-12-25 16:00:51)34
- [字节豆包] #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct sqlist //单链表结构体 { int data; struct sqlist *next; //指针域 }sqlist; void initlist (sqlist *l, sqlist *m, sqlist *n, sqlist *h) { //todo list yes l->next = null; m->next = null; n->next = null; h->next = null; } void emp(sqlist *l) { if (l->next==null) //todo list)yes printf("链表为空表。\n"); else printf("链表为非空表。\n"); } void length(sqlist *l) { sqlist *p; int length = 0; p=l->next; while(p!=null)(428点数解答 | 2024-10-23 23:09:51)251
- [字节豆包] 6-1 日期几何 分数 10 作者 Happyer 单位 湖北文理学院 关于日期的结构定义如下: struct DateG{ int yy,mm,dd;}; 编写两个函数,一个计算自公元1年1月1日到指定的日期共经历了多少天。另一个是前一个函数的逆函数:由自公元1年1月1日历经指定的天数后的日期(返回年月日构成的日期)。 函数接口定义: struct DateG days2Date(int x);{//from:{1,1,1} + 100-->{1,4,11} int Days(DateG x);// {2,,4,11} return 465 from{1,1,1} 裁判测试程序样例: struct DateG{ int yy,mm,dd; }; char leapYear(int year);//闰年否 struct DateG _DateG(char *st);{//"1919-9-9"-->{1919,9,9} struct DateG Add(struct DateG x,int y);//{1919,9,9}+50-->{1919,10,29}(723点数解答 | 2025-12-11 13:16:19)34
- [字节豆包] 6-1 日期几何 分数 10 作者 Happyer 单位 湖北文理学院 关于日期的结构定义如下: struct DateG{ int yy,mm,dd;}; 编写两个函数,一个计算自公元1年1月1日到指定的日期共经历了多少天。另一个是前一个函数的逆函数:由自公元1年1月1日历经指定的天数后的日期(返回年月日构成的日期)。 函数接口定义: struct DateG days2Date(int x);{//from:{1,1,1} + 100-->{1,4,11} int Days(DateG x);// {2,,4,11} return 465 from{1,1,1} 裁判测试程序样例: struct DateG{ int yy,mm,dd; }; char leapYear(int year);//闰年否 struct DateG _DateG(char *st);{//"1919-9-9"-->{1919,9,9} struct DateG Add(struct DateG x,int y);//{1919,9,9}+50-->{1919,10,29}(1188点数解答 | 2025-12-12 20:17:01)29