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

时间限制: 1 Sec  内存限制: 128 MB

提交: 576  解决: 280

题目描述

编写一个函数creatlink,用来建立一个动态链表。(包含学号和成绩)

编写一个函数printlink,用来输出一个链表。

编写一个函数dellink,用来删除动态链表中一个指定的结点(由实参指定某一学号,表示要删除该学生结点)。

编写一个函数insertlink,用来向动态链表插入一个结点。

编写一个函数freelink,用来释放一个动态链表。

输入

输入多个学生的学号和成绩,建立动态链表,以0 0 结束

输入学号,删除链表中的对应结点

插入两个链表结点

输出

输出的链表

样例输入

1001 100
1002 95
1005 90
1008 76
0 0
1005
1006 98
1009 99

样例输出

1001 100.00
1002 95.00
1006 98.00
1008 76.00
1009 99.00

提示

主函数已给定如下,提交时不需要包含下述主函数







/* C代码 */



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;



}







/* C++代码 */







int main()



{



    student *creatlink(void);



    student *dellink(student *,long);



    student *insertlink(student *,student *);



    void printlink(student *);



    void freelink(student *);



    student *head,stu;



    long del_num;



    head=creatlink();



    cin>>del_num;



    head=dellink(head,del_num);



    cin>>stu.num>>stu.score;



    head=insertlink(head,&stu);



    cin>>stu.num>>stu.score;



    head=insertlink(head,&stu);



    cout<<setiosflags(ios::fixed);



    cout<<setprecision(2);



    printlink(head);



    freelink(head);



    return 0;



}

迷失在幽谷中的鸟儿,独自飞翔在这偌大的天地间,却不知自己该飞往何方……

#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<iomanip>
using namespace std;
struct student
{
long int num;
float score;
struct student *next;
};
struct student *creatlink()
{
struct student *p1,*p2,*head=NULL;
p1=p2=(struct student*)malloc(sizeof(struct student));
while(~scanf("%ld%f",&p1->num,&p1->score)&&(p1->score||p1->num))
{
if(head==NULL)head=p1;
else p2->next=p1;
p2=p1;
p1=p1->next=(struct student*)malloc(sizeof(struct student));
}
p2->next=NULL;
return head;
};
struct student *dellink(struct student *a,long b)
{
struct student *head=a,*p=a,*p2=a;
while(p!=NULL)
{
if(p->num==b)
p2->next=p->next;
p2=p;
p=p->next;
}
return head;
};
struct student *insertlink(struct student *a,struct student *b)
{
struct student *head=a,*p=a,*p2=a,*k;
k=(struct student*)malloc(sizeof(struct student));
k->num=b->num,k->score=b->score;
int n=0;
while(p!=NULL)
{
if(p->num>b->num)
{
p2->next=k;
k->next=p;
n=1;
}
p2=p;
p=p->next;
}
if(n==0)p2->next=k,k->next=NULL;
return head;
};
void printlink(struct student *a)
{
struct student *p=a;
while(p!=NULL)
{
printf("%ld %.2f\n",p->num,p->score);
p=p->next;
}
}
void freelink(struct student *a)
{
while(a!=NULL)
{
delete(a);
a=a->next;
}
}
int main()
{
student *creatlink(void);
student *dellink(student *,long);
student *insertlink(student *,student *);
void printlink(student *);
void freelink(student *);
student *head,stu;
long del_num;
head=creatlink();
cin>>del_num;
head=dellink(head,del_num);
cin>>stu.num>>stu.score;
head=insertlink(head,&stu);
cin>>stu.num>>stu.score;
head=insertlink(head,&stu);
cout<<setiosflags(ios::fixed);
cout<<setprecision(2);
printlink(head);
freelink(head);
return 0;
}

YTU 2430: C语言习题 链表建立,插入,删除,输出的更多相关文章

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

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

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

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

  3. Problem A: C语言习题 链表建立,插入,删除,输出

    #include<stdio.h> #include<string.h> #include<stdlib.h> typedef struct student { l ...

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

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

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

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

  6. YTU 2414: C语言习题 字符串排序

    2414: C语言习题 字符串排序 时间限制: 1 Sec  内存限制: 128 MB 提交: 656  解决: 305 题目描述 输入n个字符串,将它们按字母由小到大的顺序排列并输出.编写三个函数实 ...

  7. YTU 2974: C语言习题5.26--文件操作3

    2974: C语言习题5.26--文件操作3 时间限制: 1 Sec  内存限制: 128 MB 提交: 213  解决: 92 题目描述 文本文件score.dic 中存储了n名学生的信息(班级编号 ...

  8. YTU 2973: C语言习题5.25--文件操作2

    2973: C语言习题5.25--文件操作2 时间限制: 1 Sec  内存限制: 128 MB 提交: 242  解决: 105 题目描述 文本文件score.dic 中存储了n名学生的信息(班级编 ...

  9. YTU 2972: C语言习题5.24--文件操作1

    2972: C语言习题5.24--文件操作1 时间限制: 1 Sec  内存限制: 128 MB 提交: 248  解决: 94 题目描述 文本文件score.dic 中存储了n名学生的信息(班级编号 ...

随机推荐

  1. Java基础学习总结(93)——Java编码规范之代码性能及惯例

    1.避免使用包装类构造函数 按照SUN公司的说明,使用自动装箱或静态工厂方法比使用new一个对象快3到4倍,该规则可以用在valueOf或其它静态工厂的调用中(如:Short.Integer, Lon ...

  2. oracle备份表和数据

    oracle 备份数据 如果备份表存在 原表t_base_employee,备份表t_base_employee20180718 insert into t_base_employee0718 sel ...

  3. hexo干货系列:(总纲)搭建独立博客初衷

    前言 我是一名程序员,以前知识整理都是整理在为知笔记上,博客用的比较少,更别说是使用独立博客,因为不会... 2016年过年在家期间偶然的机会萌发了自己要搭建一个属于自己的独立博客的想法,于是就有了下 ...

  4. BZOJ:[JSOI2009]游戏Game【二分图匹配乱搞】

    题目大意:n*m的棋盘,其中有些区域是禁区,两个人在棋盘上进行博弈,后手选择棋子的初始位置,然后先后手轮流将棋子往上下左右移动,走过的区域不能再走,问能否有一个位置使得后手必胜 Input 输入数据首 ...

  5. 【HDOJ6318】Swaps and Inversions(树状数组)

    题意: 给定一串数组,其中含有一个逆序对则需要花费x,交换相邻两个数需要花费y,输出最小花费. n<=1e5,-1e9<=a[i]<=1e9 思路: #include<cstd ...

  6. JS中的call()和apply()方法区别

    如 果没接触过动态语言,以编译型语言的思维方式去理解javaScript将会有种神奇而怪异的感觉,因为意识上往往不可能的事偏偏就发生了,甚至觉得不可 理喻.如果在学JavaScript这自由而变幻无穷 ...

  7. UITextInputMode currentInputMode is deprecated. 警告的解决

    如果你的工程最低支持版本为7.0 你会发现有警告 : 'currentInputMode' is deprecated: first deprecated in iOS 7.0 替换方案:UIText ...

  8. 为什么utf8占用3个字节

    UNICODE是万能编码,包含了所有符号的编码,它规定了所有符号在计算机底层的二进制的表示顺序.有关Unicode为什么会出现就不叙述了,Unicode是针对所有计算机的使用者定义一套统一的编码规范, ...

  9. eclipse bug之'<>'operator is not allowed for source level below 1.7

    eclipse中导入工程,报这个错'<>'operator is not allowed for source level below 1.7,把jdk改成1.7后,提示Android r ...

  10. 利用NSA的MS17-010漏洞利用工具实现Win 7和Win Server 2008系统入侵

    影子经纪人(Shadow Brokers)最近陆续曝光的NSA网络武器令人震惊,尽管这些工具是否出自国家级别黑客团队之手尚不清楚,但至少存在一个可以说明问题的事实:这些漏洞利用工具都能有效运行,且具有 ...