#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语言习题 链表建立,插入,删除,输出的更多相关文章

  1. C语言习题 链表建立,插入,删除,输出

    Problem B: C语言习题 链表建立,插入,删除,输出 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 222  Solved: 92 [Subm ...

  2. YTU 2430: C语言习题 链表建立,插入,删除,输出

    2430: C语言习题 链表建立,插入,删除,输出 时间限制: 1 Sec  内存限制: 128 MB 提交: 576  解决: 280 题目描述 编写一个函数creatlink,用来建立一个动态链表 ...

  3. Problem X: C语言习题 学生成绩输入和输出

    Problem X: C语言习题 学生成绩输入和输出 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 4722  Solved: 2284[Submit] ...

  4. Problem Q: C语言习题 计算该日在本年中是第几天

    Problem Q: C语言习题 计算该日在本年中是第几天 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 4572  Solved: 2474[Subm ...

  5. YTU 2429: C语言习题 学生成绩输入和输出

    2429: C语言习题 学生成绩输入和输出 时间限制: 1 Sec  内存限制: 128 MB 提交: 1897  解决: 812 题目描述 编写一个函数print,打印一个学生的成绩数组,该数组中有 ...

  6. 20140502 static_cast和dynamic_cast的类型检查 双链表建立,删除,打印

    1.static_cast和dynamic_cast的类型检查 static_cast的类型检查:只检查无关类之间的转换 CBaseY* pY1 = static_cast<CBaseY*> ...

  7. 链表的C++实现——创建-插入-删除-输出-清空

    注:学习了数据结构与算法分析后,对链表进行了C++实现,参考博文:http://www.cnblogs.com/tao560532/articles/2199280.html 环境:VS2013 // ...

  8. 单链表的插入删除操作(c++实现)

    下列代码实现的是单链表的按序插入.链表元素的删除.链表的输出 // mylink.h 代码 #ifndef MYLINK_H #define MYLINK_H #include<iostream ...

  9. [PHP] 数据结构-链表创建-插入-删除-查找的PHP实现

    链表获取元素1.声明结点p指向链表第一个结点,j初始化1开始2.j<i,p指向下一结点,因为此时p是指向的p的next,因此不需要等于3.如果到末尾了,p还为null,就是没有查找到 插入元素1 ...

随机推荐

  1. 51nod1010(枚举+二分)

    题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1010 题意:中文题诶- 思路:求第一个比 x (1<= ...

  2. 图解linux安装hadoop

    安装步骤: 一.准备工作 1.解压文件 [root@localhost soft]# tar -zxvf hadoop-2.4.1.tar.gz 2.改名: [root@localhost soft] ...

  3. 洛谷P1038 神经网络

    P1038 神经网络 题目背景 人工神经网络(Artificial Neural Network)是一种新兴的具有自我学习能力的计算系统,在模式识别.函数逼近及贷款风险评估等诸多领域有广泛的应用.对神 ...

  4. spark sql 导出数据

    如果用户希望在spark sql 中,执行某个sql 后,将其结果集保存到本地,并且指定csv 或者 json 格式,在 beeline 中,实现起来很麻烦.通常的做法是将其create table ...

  5. 帝都Day3——各种dp

    备注:Day1 Day2记得笔记太233,所以就不发了 备注2:Day4~Day7发不发看心情qaq (7.17持续更新中...) 动态规划A 记忆化搜索 & 动态规划初步 8点15: 杨姓d ...

  6. HDU 6447 YJJ’s Salesman (树状数组 + DP + 离散)

    题意: 二维平面上N个点,从(0,0)出发到(1e9,1e9),每次只能往右,上,右上三个方向移动, 该N个点只有从它的左下方格点可达,此时可获得收益.求该过程最大收益. 分析:我们很容易就可以想到用 ...

  7. IfmContextHolder(ThreadLocal)

    package com.yundaex.wms.config; public class IfmContextHolder { private static final ThreadLocal< ...

  8. spring动态线程池(实质还是用了java的线程池)

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  9. PullToRefreshListView

    @Override protected void onRefreshing(final boolean doScroll) { /** * If we're not showing the Refre ...

  10. Hive 基本语法操练(四):Hive 复合类型

    hive语法中主要提供了以下复合数据类型: 1)Structs: structs内部的数据可以通过DOT(.)来存取.例如,表中一列c的类型为STRUCT{a INT; b INT},我们可以通过c. ...