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. asp.net静态变量研究

    asp.net的webform,请求一个页面,如index.aspx,每一次都会交给不同的线程来处理. 经过个人测试,不管是页面类的静态属性,还是工具类的静态属性,都不会因为session的过期而改变 ...

  2. K-means算法-聚类

    算法过程如下: 1)从N个文档随机选取K个文档作为质心 2)对剩余的每个文档测量其到每个质心的距离,并把它归到最近的质心的类 3)重新计算已经得到的个各类的质心 4)迭代2~3步直至新的质心与原质心相 ...

  3. C 题 KMP中next[]问题

    题目大意: 找到能够进行字符串匹配的前缀 这题只要一直求next,直到next为0停止,记得答案是总长减去next的长度 #include <iostream> #include < ...

  4. [NOIP2000] 提高组 洛谷P1022 计算器的改良

    题目背景 NCL是一家专门从事计算器改良与升级的实验室,最近该实验室收到了某公司所委托的一个任务:需要在该公司某型号的计算器上加上解一元一次方程的功能.实验室将这个任务交给了一个刚进入的新手ZL先生. ...

  5. Python()- 面向对象的组合用法

    面向对象的组合用法 一个类中以另一个类的对象作为数据属性(一个类中引用另一个类的对象)一种 "有" 的关系: 比如:定义 1个人类 & 1个武器类 然后 张三 有 枪 李四 ...

  6. CodeForces 596B Wilbur and Array

    简单题,一个一个操作,最后就是答案. #include<cstdio> #include<cstring> #include<cmath> #include< ...

  7. API StringBuffer类例子

    package cn.zmh.Buffer; public class StringBufferDemo { public static void main(String[] args) { prin ...

  8. Enhance Magento 404 page

    Magento default installation already has a predefined custom 404 page (no-route). But is it enough t ...

  9. [教程]Delphi 中三种回调函数形式解析

    Delphi 支持三种形式的回调函数 全局函数这种方式几乎是所有的语言都支持的,类的静态函数也可以归为此类,它保存的只是一个函数的代码起始地址指针( Pointer ).在 Delphi 中声明一般为 ...

  10. 使用POI操作Excel时new XSSFWorkbook ()报错java.lang.NoSuchMethodError解决方式

    使用最新的POI3.11时,在执行 Workbook  workBook = new XSSFWorkbook ();这段代码时出现错误: java.lang.NoSuchMethodError: j ...