酷代码 AI
菜单

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点数解答]

服务商
相关提问
发财导航,免费问AI
实用工具查看更多