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 ...
随机推荐
- 清北刷题冲刺 11-02 p.m
函数最值 #include<iostream> #include<cstdio> #include<cstring> #define maxn 100010 usi ...
- vue2格式化时间戳
注意:时间戳分为10位和13位的,10位的是秒,13位的是毫秒 这里给出的是格式化13位的方法,10位的时间戳可以加上3个0 <div id="app">{{time ...
- EIGRP-1-EIGRP的基础和演变
值得一提的是,在2013年,Cisco决定开放EIGRP的定义,并将其发布为IETFInternet草案,即RFC的前身:文档名称为draft-savage-eigrp.从此,基本的EIGRP不再是机 ...
- ES6扩展运算符...进行的数组删除
今天写了按照React小书写了Reducer,发现基础真是太重要了,所有关于上层建筑的细节都需要回到下层细节中去寻找,而且现在的基础也由ES3变成了ES6了. const ADD_USER = &qu ...
- HelloSpock
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- java 单例模式之线程安全的饿汉模式和懒汉模式
转载博主:thankyou https://blog.csdn.net/twj13162380953/article/details/53869983 理解: 饿汉式获取实例的步骤简单所以线程更安全. ...
- Python时间与日期操作(datetime、time、calendar)
相关模块 模块 说明 time time是一个仅包含与日期和时间相关的函数和常量的模块,在本模块中定义了C/C++编写的几个类.例如,struct_time类 datetime datetime是一个 ...
- PHP异步任务worker
1.概述 异步任务框架主要包含两个角色: WorkerServer主要负责管理(启动,重启,监控等)worker工作进程. Worker负责从指定消息队列获取任务消息并执行任务. 为了提高worker ...
- UVALive 4262——Trip Planning——————【Tarjan 求强连通分量个数】
Road Networks Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Stat ...
- MySQL中有关TIMESTAMP和DATETIME的对比
TIMESTAMP和DATETIME的相同点: 1> 两者都可用来表示YYYY-MM-DD HH:MM:SS[.fraction]类型的日期. TIMESTAMP和DATETIME的不同点: 1 ...