已知一个带头结点的单链表L,其结点数据为整型,请给出用C语言描述的该链表的数据结构定义,并编写算法删除链表L中所有的数据为奇数的结点,并输
出删除后链表的所有数据。
考研数据结构算法设计题 链表算法设计题
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- CSDN专家-天际的海浪 2021-11-06 03:26关注
你题目的解答代码如下:
#include <stdio.h> #include <stdlib.h> struct Data { int numb; struct Data *next; }; void creat(struct Data *pHead) { int count = 1; struct Data *p, *t; pHead->next = NULL; p = pHead; while (count<10) { t = (struct Data *)malloc(sizeof(struct Data)); t->numb = count; t->next = NULL; p->next = t; p = t; count++; } } void del(struct Data *pHead) { struct Data *q, *p = pHead; while (p->next != NULL) { q = p; p = p->next; if (p->numb%2==1) { printf("删除 %d\n", p->numb); q->next = p->next; p = q; } } } void print(struct Data *pHead) { struct Data *p = pHead; while (p->next != NULL) { p = p->next; printf("%d ", p->numb); } printf("\n"); } int main() { struct Data *pHead = (struct Data *)malloc(sizeof(struct Data)); creat(pHead); print(pHead); del(pHead); print(pHead); return 0; }
如有帮助,望采纳!谢谢!
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 2无用
悬赏问题
- ¥15 永磁直线电机的电流环pi调不出来
- ¥15 用stata实现聚类的代码
- ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
- ¥170 如图所示配置eNSP
- ¥20 docker里部署springboot项目,访问不到扬声器
- ¥15 netty整合springboot之后自动重连失效
- ¥15 悬赏!微信开发者工具报错,求帮改
- ¥20 wireshark抓不到vlan
- ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
- ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持