YTU 2430: C语言习题 链表建立,插入,删除,输出
来源:互联网 发布:淘宝虚拟物品货源 编辑:程序博客网 时间:2024/05/21 09:39
2430: C语言习题 链表建立,插入,删除,输出
时间限制: 1 Sec 内存限制: 128 MB提交: 576 解决: 280
题目描述
编写一个函数creatlink,用来建立一个动态链表。(包含学号和成绩)
编写一个函数printlink,用来输出一个链表。
编写一个函数dellink,用来删除动态链表中一个指定的结点(由实参指定某一学号,表示要删除该学生结点)。
编写一个函数insertlink,用来向动态链表插入一个结点。
编写一个函数freelink,用来释放一个动态链表。
输入
输入多个学生的学号和成绩,建立动态链表,以0 0 结束
输入学号,删除链表中的对应结点
插入两个链表结点
输出
输出的链表
样例输入
1001 1001002 951005 901008 760 010051006 981009 99
样例输出
1001 100.001002 95.001006 98.001008 76.001009 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;
}
/* 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;}
#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;}
1 0
- YTU 2430: C语言习题 链表建立,插入,删除,输出
- C语言习题 链表建立,插入,删除,输出
- YTU 2416: C语言习题 成绩输出
- YTU 2425: C语言习题 输出月份
- YTU:C语言习题 输出月份
- 链表的建立,输出,删除,插入运算的c语言实现
- C 动态链表的建立,输出,删除,插入
- YTU 2429: C语言习题 学生成绩输入和输出
- [YTU]_2429( C语言习题 学生成绩输入和输出)
- C语言链表的插入和删除、建立
- C语言链表的建立、插入和删除
- 链表建立,插入,删除,输出,释放
- 链表建立,插入,删除,输出
- 链表建立,插入,删除,释放,输出
- 链表建立,插入,删除,输出
- 链表建立,插入,删除,输出
- C语言实现双向链表删除、插入、双向输出
- 一道习题:链表的创建、输出、删除、插入
- 安卓开发:发送任务栏通知,并实现传值、跳转
- POJ 1426 二叉树的解法
- hdu3530Subsequence【单调队列优化dp】2010多校联合
- Hadoop 1.x 单机模式安装与测试
- boost库中计时器的使用总结(timer)
- YTU 2430: C语言习题 链表建立,插入,删除,输出
- 深入浅出C++构造函数、析构函数、深浅拷贝的相关内容
- 基础网络学习记录
- 调试CC2540遇到的小问题
- C++ 拷贝构造函数 赋值构造函数
- windows下MemCached的安装
- template关键字
- POJ NO.1182 食物链(并查集,带权并查集最优解,没有之一)
- YTU 2432: C++习题 对象数组输入与输出