#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. 2017-10-17 NOIP模拟赛

    Reverse #include<iostream> #include<cstdio> #include<cstring> using namespace std; ...

  2. github上虽然已经有实现好的Char RNN

    前言 学习RNN的时候很多人应该都有看过Andrej Karpathy写的The Unreasonable Effectiveness of Recurrent Neural Networks,使用基 ...

  3. 【常见Web应用安全问题】

    Web应用程序的安全性问题依其存在的形势划分,种类繁多,这里不准备介绍所有的,只介绍常见的一些. 常见Web应用安全问题安全性问题的列表: 1.跨站脚本攻击(CSS or XSS, Cross Sit ...

  4. C#线程入门(一)

    入门 概述与概念 创建和开始使用多线程 线程同步基础 同步要领 锁和线程安全 Interrupt 和 Abort 线程状态 等待句柄 同步环境 使用多线程 单元模式和Windows Forms Bac ...

  5. AJAX (分页)

    <!-- 企业新闻列表开始,图尺寸550*310,如果没图,则在li上加on --> <div class="common-box new-box"> &l ...

  6. 03.Spring IoC 容器 - 初始化

    基本概念 Spring IoC 容器的初始化过程在监听器 ContextLoaderListener 类中定义. 具体由该类的的 configureAndRefreshWebApplicationCo ...

  7. URAL 2080 Wallet

    找规律发现只要找到两个相同数字之间,有多少个不同的数字,即为答案. 可以用树状数组离线处理. 坑点是卡有很多张,没用完的情况,后面的卡直接放在哪里, 就是 10 5 1 2 3 4 5 这样 开始数据 ...

  8. Unity UGUI按钮添加点击事件

    1. 可视化创建及事件绑定 # 1 : 通过 Hierarchy 面板创建 UI > Button. 2 : 创建一个脚本 TestClick.cs, 定义了一个 Click 的 public ...

  9. (转)不看绝对后悔的Linux三剑客之grep实战精讲

    不看绝对后悔的Linux三剑客之grep实战精讲 原文:http://blog.51cto.com/hujiangtao/1923675 https://www.cnblogs.com/peida/a ...

  10. 使用tortoise git将一个现有项目推送到远程仓库

    一.安装文件: 1.git https://git-scm.com/downloads 2.tortoise git https://tortoisegit.org/download/ 二.将一个现有 ...