谭浩强第四版第九章课后习题12>>>建立一个链表,每个节点包括:学号、姓名、性别、年龄。输入一个年龄,若链表 中的结点所包含的年龄等于此年龄,则删除此结点。
- #include<stdio.h>
- #include<stdlib.h>
- #define N sizeof(link)
- typedef struct lin
- {
- struct lin *next;
- int num;
- char name[];
- char sex;
- int age;
- }link;
- void print(link *head)
- {
- link *p;
- p=head;
- printf("打印数据如下:\n");
- while(p)
- {
- printf("%d\t%s\t%c\t%d\n",p->num,p->name,p->sex,p->age);
- p=p->next;
- }
- }
- int n;
- link *creat(void)
- {
- link *head,*p,*s;
- p=s=(link *)malloc(N);
- printf("请输入输数据:\n");
- scanf("%d %s %c %d",&p->num,p->name,&p->sex,&p->age);
- head=p;
- n=;
- while(p->num!=)
- {
- n++;
- if(n!=)s->next=p;
- s=p;
- p=(link*)malloc(N);
- printf("请输入数据1:\n");
- scanf("%d %s %c %d",&p->num,p->name,&p->sex,&p->age);
- }
- s->next=NULL;
- return(head);
- }
- link *del(link *head,int a)
- {
- link *p,*p1,*s;
- for(p=p1=head;p;)
- {
- if(p->age==a)
- if(p==head)
- {
- s=p;
- head=p=p->next;
- free(s);
- }
- else
- {
- p1->next=p->next;
- s=p;
- p=p->next;
- free(s);
- }
- else
- {
- p1=p;
- p=p->next;
- }
- }
- return(head);
- }
- int main()
- {
- link *head,*p;
- int a;
- head=creat();
- printf("打印处理前的数据:\n");
- print(head);
- printf("请输入年龄:\n");
- scanf("%d",&a);
- p=del(head,a);
- printf("打印处理后的数据: \n");
- print(p);
- return ;
- }
测试结果:
- 请输入输数据:
- Li F
- 请输入数据1:
- Wang M
- 请输入数据1:
- Sun F
- 请输入数据1:
- CH M
- 请输入数据1:
- QIn F
- 请输入数据1:
- Kun F
- 请输入数据1:
- Jun M
- 请输入数据1:
- Xun F
- 请输入数据1:
- Liu M
- 请输入数据1:
- 打印处理前的数据:
- 打印数据如下:
- Li F
- Wang M
- Sun F
- CH M
- QIn F
- Kun F
- Jun M
- Xun F
- Liu M
- 请输入年龄:
- 打印处理后的数据:
- 打印数据如下:
- Wang M
- Sun F
- QIn F
- Kun F
- Xun F
- Press any key to continue
谭浩强第四版第九章课后习题12>>>建立一个链表,每个节点包括:学号、姓名、性别、年龄。输入一个年龄,若链表 中的结点所包含的年龄等于此年龄,则删除此结点。的更多相关文章
- 谭浩强C语言第四版第九章课后习题7--9题(建立,输出,删除,插入链表处理)
#include<stdio.h> #include<stdlib.h> #define N sizeof(link) typedef struct stu { struct ...
- c++面向对象程序设计 课后题 答案 谭浩强 第四章
c++面向对象程序设计课后题答案 谭浩强 第四章 1: #include <iostream> using namespace std; class Complex {public: Co ...
- java编程思想第四版第九章总结
1. 策略设计模式 参考这篇文章:http://blog.csdn.net/chenjie19891104/article/details/6396458 讲的很清楚,策略设计模式.并且举了一个例子, ...
- java编程思想第四版第九章习题
第三题 package net.mindview.interfaces; abstract class Base{ public Base(){ print(); } abstract void pr ...
- 挂羊头卖狗肉蓄意欺骗读者——谭浩强《C程序设计(第四版)》中所谓的“按照C99”(二)
挂羊头卖狗肉蓄意欺骗读者——谭浩强<C程序设计(第四版)>中所谓的“按照C99”(二) 在<谭C>p4:“本书的叙述以C99标准为依据”,下面从C89到C99的主要变化方面来看 ...
- C程序设计(谭浩强)第五版课后题答案 第一章
大家好,这篇文章分享了C程序设计(谭浩强)第五版课后题答案,所有程序已经测试能够正常运行,如果小伙伴发现有错误的的地方,欢迎留言告诉我,我会及时改正!感谢大家的观看!!! 1.什么是程序?什么是程序设 ...
- c++面向对象程序设计 谭浩强 第一章答案
c++面向对象程序设计 谭浩强 答案 第一章 目录: c++面向对象程序设计 谭浩强 答案 第一章 c++面向对象程序设计 谭浩强 答案 第二章 c++面向对象程序设计 谭浩强 答案 第三章 c++面 ...
- c++面向对象程序设计 谭浩强 第三章答案
2: #include <iostream> using namespace std; class Date {public: Date(int,int,int); Date(int,in ...
- c++面向对象程序设计 谭浩强 第二章答案
类体内定义成员函数 #include <iostream> using namespace std; class Time { public: void set_time(); void ...
随机推荐
- Python的线程池实现
# -*- coding: utf-8 -*- #Python的线程池实现 import Queue import threading import sys import time import ur ...
- 基于CAS的SSO单点登录-实现ajax跨域访问的自动登录(也相当于超时重连)
先补课,以下网址可以把CAS环境搭起来. [JA-SIG CAS服务环境搭建]http://linliangyi2007.iteye.com/blog/165307 [JA-SIG CAS业务架构介绍 ...
- laravel5.4学习笔记
1.安装laravel可以直接用composer安装,然后用laravel new xxx来新建项目 服务器上安装了composer(php包管理工具)以后, composer global requ ...
- 诊断GRID无法启动问题
诊断 Grid Infrastructure 启动问题 (文档 ID 1623340.1)
- python 带BOM头utf-8的响应解码
接口响应编码格式为带BOM头utf-8.直接获取响应的text出现乱码. '''dinghanhua2018-11requests text与content,指定响应的encoding''' api ...
- ftp免交互上传文件脚本
ftp -i -n <<! open .x.x.x user yourFtpAccount yourPasswd cd /root/DailyBuild/webapps/ delete x ...
- c#加一个后台线程
- 【luogu P1821 [USACO07FEB]银牛派对Silver Cow Party】 题解
题目链接:https://www.luogu.org/problemnew/show/P1821 反向多存一个图,暴力跑两遍 #include <cstdio> #include < ...
- Android学习笔记_17_Intent匹配规则(隐式意图)
Android基本的设计理念是鼓励减少组件间的耦合,因此Android提供了Intent (意图) ,Intent提供了一种通用的消息系统,它允许在你的应用程序与其它的应用程序间传递Intent来执行 ...
- HDU 1180 诡异的楼梯(超级经典的bfs之一,需多回顾)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1180 诡异的楼梯 Time Limit: 2000/1000 MS (Java/Others) ...