Problem A: C语言习题 链表建立,插入,删除,输出
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef struct student
{
long num;
float score;
struct student *next;
}student;
student *creatlink(void)
{
student *head = NULL;
student *last , *p ;
p =(student *)malloc(sizeof(student));
scanf("%ld%f",&p->num,&p->score);
while(p->num!=0)
{
if(head==NULL)
{
head=p;
}
else
last->next=p;
last=p;
p =(student *)malloc(sizeof(student));
scanf("%ld %f",&p->num,&p->score);
}
last->next=NULL;
free(p);
return head;
}
student *dellink(student *head,long del)
{
student *p1=head,*p;
while(p1)
{
if(del==p1->num)
{
p->next=p1->next;
free(p1);
break;
}
else
{
p=p1;
p1=p1->next;
}
}
return head;
}
void printlink(struct student *head)
{
while(head!=NULL)
{
printf("%ld %.2f\n",head->num,head->score);
head=head->next;
}
}
void freelink(struct student *head)
{
student *p1=head;
student *p;
while(p1)
{
p=p1->next;
free(p1);
p1=p;
}
}
student *insertlink(student *head,student *stu)
{
student *p=head;
student *pe;
student *last=NULL;
student *newbase=(student *)malloc(sizeof(student));
newbase->num=stu->num;
newbase->score=stu->score;
newbase->next=NULL;
if(newbase==NULL)
exit(-1);
while(p->next!=NULL)
{
p=p->next;
}
last=p;
p=head;
if(newbase->num<head->num)
{
newbase->next=head;
head=newbase;
}
else if(head->num<newbase->num&&newbase->num<last->num)
{
while((p->num<=newbase->num)&&(p->next!=NULL))
{
pe=p;
p=p->next;
}
newbase->next=p;
pe->next=newbase;
}
else
last->next=newbase;
return head;
} int main() { struct student *creatlink(void); struct student *dellink(struct student *,long); struct student *insertlink(struct student *,struct student *); void printlink(struct student *); void freelink(struct student *); struct student *head,stu; long del_num; head=creatlink(); scanf("%ld",&del_num); head=dellink(head,del_num); scanf("%ld%f",&stu.num,&stu.score); head=insertlink(head,&stu); scanf("%ld%f",&stu.num,&stu.score); head=insertlink(head,&stu); printlink(head); freelink(head); return 0; }
Problem A: C语言习题 链表建立,插入,删除,输出的更多相关文章
- C语言习题 链表建立,插入,删除,输出
Problem B: C语言习题 链表建立,插入,删除,输出 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 222 Solved: 92 [Subm ...
- YTU 2430: C语言习题 链表建立,插入,删除,输出
2430: C语言习题 链表建立,插入,删除,输出 时间限制: 1 Sec 内存限制: 128 MB 提交: 576 解决: 280 题目描述 编写一个函数creatlink,用来建立一个动态链表 ...
- Problem X: C语言习题 学生成绩输入和输出
Problem X: C语言习题 学生成绩输入和输出 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 4722 Solved: 2284[Submit] ...
- Problem Q: C语言习题 计算该日在本年中是第几天
Problem Q: C语言习题 计算该日在本年中是第几天 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 4572 Solved: 2474[Subm ...
- YTU 2429: C语言习题 学生成绩输入和输出
2429: C语言习题 学生成绩输入和输出 时间限制: 1 Sec 内存限制: 128 MB 提交: 1897 解决: 812 题目描述 编写一个函数print,打印一个学生的成绩数组,该数组中有 ...
- 20140502 static_cast和dynamic_cast的类型检查 双链表建立,删除,打印
1.static_cast和dynamic_cast的类型检查 static_cast的类型检查:只检查无关类之间的转换 CBaseY* pY1 = static_cast<CBaseY*> ...
- 链表的C++实现——创建-插入-删除-输出-清空
注:学习了数据结构与算法分析后,对链表进行了C++实现,参考博文:http://www.cnblogs.com/tao560532/articles/2199280.html 环境:VS2013 // ...
- 单链表的插入删除操作(c++实现)
下列代码实现的是单链表的按序插入.链表元素的删除.链表的输出 // mylink.h 代码 #ifndef MYLINK_H #define MYLINK_H #include<iostream ...
- [PHP] 数据结构-链表创建-插入-删除-查找的PHP实现
链表获取元素1.声明结点p指向链表第一个结点,j初始化1开始2.j<i,p指向下一结点,因为此时p是指向的p的next,因此不需要等于3.如果到末尾了,p还为null,就是没有查找到 插入元素1 ...
随机推荐
- c/c++/c# 快速计算 Cumulative Normal Distribution 正态累积函数CDF
链接: http://stackoverflow.com/questions/2328258/cumulative-normal-distribution-function-in-c-c http:/ ...
- 洛谷P3068 [USACO13JAN]派对邀请函Party Invitations
P3068 [USACO13JAN]派对邀请函Party Invitations 题目描述 Farmer John is throwing a party and wants to invite so ...
- 2017-10-4 清北刷题冲刺班a.m
P101zhx a [问题描述]你是能看到第一题的 friends 呢.——hjaHja 拥有一套时光穿梭技术,能把字符串以超越光速的速度传播,但是唯一的问题是可能会 GG.在传输的过程中,可能有四种 ...
- android手机设备查看/data/data
打开cmd 进入安卓 SDK的'Platform tools' cd F:\software\adt-bundle-windows-x86_64-20130522\sdk\platform-too ...
- Java: 面向对象程序设计(上)
1. 类 类主要包含3个部分: 类属性:用来描述类本身所抽象出的事物的属性 类方法:用来描述这个被抽象出的事物可以做什么 构造方法:每个类都至少会有一个特殊的方法,该方法提供了创建类对象的初始化机制 ...
- 将Python的.py文件转变为可执行文件.exe
python是个很强大的工具,但我们生成的.py文件在没有Python环境下运行就需要转为.exe文件,我使用的是PyInstaller 1.安装PyInstaller: pip install Py ...
- ng2学习--pipe使用
We use our custom pipe the same way we use built-in pipes.(自定义Pipe和API里自带的Pipe使用方式一致) We must includ ...
- POJ1151 Atlantis 线段树扫描线
扫描线终于看懂了...咕咕了快三个月$qwq$ 对于所有的横线按纵坐标排序,矩阵靠下的线权值设为$1$,靠上的线权值设为$-1$,然后执行线段树区间加减,每次的贡献就是有效宽度乘上两次计算时的纵坐标之 ...
- 华东交通大学2017年ACM“双基”程序设计竞赛 1003
Problem Description 有两个球在长度为L的直线跑道上运动,两端为墙.0时刻小球a以1m/s的速度从起点向终点运动,t时刻小球b以相同的速度从终点向起点运动.问T时刻两球的距离.这里小 ...
- linux中的三种时间
mtime [修改时间] 文件/目录的修改时间 ctime [属性修改时间] 文件目录的属性的修改时间 atime [访问时间]文件/目录的访问时间 stat 123.txt File: `1 ...