1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #define N sizeof(link)
  4. typedef struct lin
  5. {
  6. struct lin *next;
  7. int num;
  8. char name[];
  9. char sex;
  10. int age;
  11. }link;
  12. void print(link *head)
  13. {
  14. link *p;
  15. p=head;
  16. printf("打印数据如下:\n");
  17. while(p)
  18. {
  19. printf("%d\t%s\t%c\t%d\n",p->num,p->name,p->sex,p->age);
  20. p=p->next;
  21. }
  22. }
  23. int n;
  24. link *creat(void)
  25. {
  26. link *head,*p,*s;
  27. p=s=(link *)malloc(N);
  28. printf("请输入输数据:\n");
  29. scanf("%d %s %c %d",&p->num,p->name,&p->sex,&p->age);
  30. head=p;
  31. n=;
  32. while(p->num!=)
  33. {
  34. n++;
  35. if(n!=)s->next=p;
  36. s=p;
  37. p=(link*)malloc(N);
  38. printf("请输入数据1:\n");
  39. scanf("%d %s %c %d",&p->num,p->name,&p->sex,&p->age);
  40. }
  41. s->next=NULL;
  42. return(head);
  43. }
  44. link *del(link *head,int a)
  45. {
  46. link *p,*p1,*s;
  47. for(p=p1=head;p;)
  48. {
  49. if(p->age==a)
  50. if(p==head)
  51. {
  52. s=p;
  53. head=p=p->next;
  54. free(s);
  55. }
  56. else
  57. {
  58. p1->next=p->next;
  59. s=p;
  60. p=p->next;
  61. free(s);
  62.  
  63. }
  64. else
  65. {
  66. p1=p;
  67. p=p->next;
  68. }
  69. }
  70. return(head);
  71. }
  72. int main()
  73. {
  74. link *head,*p;
  75. int a;
  76. head=creat();
  77. printf("打印处理前的数据:\n");
  78. print(head);
  79. printf("请输入年龄:\n");
  80. scanf("%d",&a);
  81. p=del(head,a);
  82. printf("打印处理后的数据: \n");
  83. print(p);
  84. return ;
  85. }

测试结果:

  1. 请输入输数据:
  2. Li F
  3. 请输入数据1
  4. Wang M
  5. 请输入数据1
  6. Sun F
  7. 请输入数据1
  8. CH M
  9. 请输入数据1
  10. QIn F
  11. 请输入数据1
  12. Kun F
  13. 请输入数据1
  14. Jun M
  15. 请输入数据1
  16. Xun F
  17. 请输入数据1
  18. Liu M
  19. 请输入数据1
  20.  
  21. 打印处理前的数据:
  22. 打印数据如下:
  23. Li F
  24. Wang M
  25. Sun F
  26. CH M
  27. QIn F
  28. Kun F
  29. Jun M
  30. Xun F
  31. Liu M
  32. 请输入年龄:
  33.  
  34. 打印处理后的数据:
  35. 打印数据如下:
  36. Wang M
  37. Sun F
  38. QIn F
  39. Kun F
  40. Xun F
  41. Press any key to continue

谭浩强第四版第九章课后习题12>>>建立一个链表,每个节点包括:学号、姓名、性别、年龄。输入一个年龄,若链表 中的结点所包含的年龄等于此年龄,则删除此结点。的更多相关文章

  1. 谭浩强C语言第四版第九章课后习题7--9题(建立,输出,删除,插入链表处理)

    #include<stdio.h> #include<stdlib.h> #define N sizeof(link) typedef struct stu { struct ...

  2. c++面向对象程序设计 课后题 答案 谭浩强 第四章

    c++面向对象程序设计课后题答案 谭浩强 第四章 1: #include <iostream> using namespace std; class Complex {public: Co ...

  3. java编程思想第四版第九章总结

    1. 策略设计模式 参考这篇文章:http://blog.csdn.net/chenjie19891104/article/details/6396458 讲的很清楚,策略设计模式.并且举了一个例子, ...

  4. java编程思想第四版第九章习题

    第三题 package net.mindview.interfaces; abstract class Base{ public Base(){ print(); } abstract void pr ...

  5. 挂羊头卖狗肉蓄意欺骗读者——谭浩强《C程序设计(第四版)》中所谓的“按照C99”(二)

    挂羊头卖狗肉蓄意欺骗读者——谭浩强<C程序设计(第四版)>中所谓的“按照C99”(二) 在<谭C>p4:“本书的叙述以C99标准为依据”,下面从C89到C99的主要变化方面来看 ...

  6. C程序设计(谭浩强)第五版课后题答案 第一章

    大家好,这篇文章分享了C程序设计(谭浩强)第五版课后题答案,所有程序已经测试能够正常运行,如果小伙伴发现有错误的的地方,欢迎留言告诉我,我会及时改正!感谢大家的观看!!! 1.什么是程序?什么是程序设 ...

  7. c++面向对象程序设计 谭浩强 第一章答案

    c++面向对象程序设计 谭浩强 答案 第一章 目录: c++面向对象程序设计 谭浩强 答案 第一章 c++面向对象程序设计 谭浩强 答案 第二章 c++面向对象程序设计 谭浩强 答案 第三章 c++面 ...

  8. c++面向对象程序设计 谭浩强 第三章答案

    2: #include <iostream> using namespace std; class Date {public: Date(int,int,int); Date(int,in ...

  9. c++面向对象程序设计 谭浩强 第二章答案

    类体内定义成员函数 #include <iostream> using namespace std; class Time { public: void set_time(); void ...

随机推荐

  1. Python的线程池实现

    # -*- coding: utf-8 -*- #Python的线程池实现 import Queue import threading import sys import time import ur ...

  2. 基于CAS的SSO单点登录-实现ajax跨域访问的自动登录(也相当于超时重连)

    先补课,以下网址可以把CAS环境搭起来. [JA-SIG CAS服务环境搭建]http://linliangyi2007.iteye.com/blog/165307 [JA-SIG CAS业务架构介绍 ...

  3. laravel5.4学习笔记

    1.安装laravel可以直接用composer安装,然后用laravel new xxx来新建项目 服务器上安装了composer(php包管理工具)以后, composer global requ ...

  4. 诊断GRID无法启动问题

    诊断 Grid Infrastructure 启动问题 (文档 ID 1623340.1)

  5. python 带BOM头utf-8的响应解码

    接口响应编码格式为带BOM头utf-8.直接获取响应的text出现乱码. '''dinghanhua2018-11requests text与content,指定响应的encoding''' api ...

  6. ftp免交互上传文件脚本

    ftp -i -n <<! open .x.x.x user yourFtpAccount yourPasswd cd /root/DailyBuild/webapps/ delete x ...

  7. c#加一个后台线程

  8. 【luogu P1821 [USACO07FEB]银牛派对Silver Cow Party】 题解

    题目链接:https://www.luogu.org/problemnew/show/P1821 反向多存一个图,暴力跑两遍 #include <cstdio> #include < ...

  9. Android学习笔记_17_Intent匹配规则(隐式意图)

    Android基本的设计理念是鼓励减少组件间的耦合,因此Android提供了Intent (意图) ,Intent提供了一种通用的消息系统,它允许在你的应用程序与其它的应用程序间传递Intent来执行 ...

  10. HDU 1180 诡异的楼梯(超级经典的bfs之一,需多回顾)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1180 诡异的楼梯 Time Limit: 2000/1000 MS (Java/Others)     ...