已知一个带头结点的单链表L,其结点数据为整型,请给出用C语言描述的该链表的数据结构定义,并编写算法删除链表L中所有的数据为奇数的结点,并输
出删除后链表的所有数据。
![](https://profile-avatar.csdnimg.cn/f81b0107a1aa46139da8227e6d179a64_m0_46486739.jpg!4)
考研数据结构算法设计题 链表算法设计题
- 写回答
- 好问题 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 PADS Logic 原理图
- ¥15 PADS Logic 图标
- ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
- ¥20 气象站点数据求取中~
- ¥15 如何获取APP内弹出的网址链接
- ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
- ¥50 STM32单片机传感器读取错误
- ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
- ¥15 机器人轨迹规划相关问题
- ¥15 word样式右侧翻页键消失