#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. 玩转Android---组件篇---Intent(意图)

    Intent的中文意思是“意图,目的”的意思,可以理解为不同组件之间通信的“媒介”或者“信使”. 目标组件一般要通过Intent来声明自己的条件,一般通过组件中的<intent-filter&g ...

  2. 简单几步实现 IOS UITextField输入长度的控制

    在ios开发过程中,我们有时候需要对UITextField的输入长度进行控制,比如输入手机号码最大长度为11位等,而ios自身又不像android那样可以设置输入框的输入长度,接下来通过简单几步实现这 ...

  3. Excel去除空行

    本文转载至:https://baijiahao.baidu.com/s?id=1590204478648348952&wfr=spider&for=pc,需要详细信息可链接查看 方法一 ...

  4. DB restore point and datagurad

    ######## 12.5.1 Flashing Back a Physical Standby Database to a Specific Point-in-Time The following ...

  5. Linux网络管理命令ifdown/ifup与ifconfig/ip中的down/up命令的对比

    参考了:https://blog.csdn.net/GDUTLYP/article/details/50498202 以下网卡均采用eth1说明. 相同点——[启用]和[禁止]网卡 ifdown et ...

  6. 【转】《Unity Shader入门精要》冯乐乐著 书中彩图

    为方便个人手机学习时候查阅,从网上转来这些彩图. 如属过当行为,联系本人删除. 勘错表 http://candycat1992.github.io/unity_shaders_book/unity_s ...

  7. Java 多线程的实现方法

    package com.jckb; /**多线程实现的两种方法 * * @author gx * */ public class Test2 { public static void main(Str ...

  8. 设置VS代码模板

    本文URL:http://www.cnblogs.com/CUIT-DX037/p/6770366.html 打开VS安装目录下:\Microsoft Visual Studio 12.0\Commo ...

  9. 妙用Object

    妙用Object 当你在写C#程序时,经常会用到“ToString()”这个方法,而且如果你细心你点就会发现所有的引用类型都含有“ToString()”这个方法,那么你知道为什么会这样吗?很简单,因为 ...

  10. 面试(Java之IO与NIO)

    一.概念 NIO即New IO,这个库是在JDK1.4中才引入的.NIO和IO有相同的作用和目的,但实现方式不同,NIO主要用到的是块,所以NIO的效率要比IO高很多.在Java API中提供了两套N ...