YTU 2601: 熟悉题型——填空题(删除线性表节点)
2601: 熟悉题型——填空题(删除线性表节点)
时间限制: 1 Sec 内存限制: 128 MB
提交: 357 解决: 212
题目描述
给出一串具体长度的数据,删除指定数据。
已经给出部分代码,
#include<iostream>
using namespace std;
struct Linklist
{
int num;
Linklist *next;
};
Linklist *creat(int l,int n)
{
Linklist *t=new Linklist;
t->num=l;//每个节点编号
if(n==1)
{
t->next=NULL;
return t;
}
cin>>l;
t->next=creat(l,n-1);
return t;
}
void printf(Linklist *p,int n)
{
if(p==NULL)
return ;
cout<<p->num;
if(n!=1)
cout<<" ";
printf(p->next,n--);
}
Linklist *dellink(Linklist *head,int num)
{
Linklist *p1,*p2;
p1=head;
while(num!=p1->num&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
/************
请补充缺少的代码,使该程序完成功能。
***************/
return head;
}
int main()
{
int n,l,m;
cin>>n;
Linklist *head;
cin>>l;
head=creat(l,n);
cin>>m;
head= dellink(head,m);
printf(head,n);
return 0;
}
输入
输入 n:6
输入数据:1 2 3 4 5 6
输入 item:5
输出
输出:1 2 3 4 6
样例输入
10
1 2 3 4 5 6 7 8 9 10
8
样例输出
1 2 3 4 5 6 7 9 10
提示
只提交注释的部分,即填写的部分。
填写的部分可能不止一行,根据自己的判断添加。
填空题添加的代码一般很短。
迷失在幽谷中的鸟儿,独自飞翔在这偌大的天地间,却不知自己该飞往何方……
#include<iostream>
using namespace std;
struct Linklist
{
int num;
Linklist *next;
};
Linklist *creat(int l,int n)
{
Linklist *t=new Linklist;
t->num=l;//每个节点编号
if(n==1)
{
t->next=NULL;
return t;
}
cin>>l;
t->next=creat(l,n-1);
return t;
}
void printf(Linklist *p,int n)
{
if(p==NULL)
return ;
cout<<p->num;
if(n!=1)
cout<<" ";
printf(p->next,n--);
}
Linklist *dellink(Linklist *head,int num)
{
Linklist *p1,*p2;
p1=head;
while(num!=p1->num&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(p1->num==num)
{
if(p1==head)
head=p1->next;
else
p2->next=p1->next;
}
return head;
}
int main()
{
int n,l,m;
cin>>n;
Linklist *head;
cin>>l;
head=creat(l,n);
cin>>m;
head=dellink(head,m);
printf(head,n);
return 0;
}
#include<iostream>
using namespace std;
struct Linklist
{
int num;
Linklist *next;
};
Linklist *creat(int l,int n)
{
Linklist *t=new Linklist;
t->num=l;//每个节点编号
if(n==1)
{
t->next=NULL;
return t;
}
cin>>l;
t->next=creat(l,n-1);
return t;
}
void printf(Linklist *p,int n)
{
if(p==NULL)
return ;
cout<<p->num;
if(n!=1)
cout<<" ";
printf(p->next,n--);
}
Linklist *dellink(Linklist *head,int num)
{
Linklist *p1,*p2;
p1=head;
while(num!=p1->num&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(p1->num==num)
{
if(p1==head)
head=p1->next;
else
p2->next=p1->next;
}
return head;
}
int main()
{
int n,l,m;
cin>>n;
Linklist *head;
cin>>l;
head=creat(l,n);
cin>>m;
head=dellink(head,m);
printf(head,n);
return 0;
}
YTU 2601: 熟悉题型——填空题(删除线性表节点)的更多相关文章
- YTU 2579: 填空题----删除指定字符
2579: 填空题----删除指定字符 时间限制: 1 Sec 内存限制: 128 MB 提交: 164 解决: 61 题目描述 小明想要做个小程序,能够删除字符串中特定的字符. 例如:想要在下面 ...
- 删除线性表中为x的元素的三种简单算法。
//删除线性表中不为x的元素. void delete_list(Sqlist &L,int x){ ; ;i < L.length;i++){ if(L.data[i] != x){ ...
- YTU 2607: A代码填空题--更换火车头
2607: A代码填空题--更换火车头 时间限制: 1 Sec 内存限制: 128 MB 提交: 91 解决: 73 题目描述 注:本题只需要提交填写部分的代码,请按照C++方式提交. 假设火车有 ...
- YTU 2605: 熟悉题型——自由设计(比较大小-类模板)
2605: 熟悉题型--自由设计(比较大小-类模板) 时间限制: 1 Sec 内存限制: 128 MB 提交: 125 解决: 107 题目描述 声明一个类模板,利用它分别实现两个整数.浮点数和字 ...
- YTU 2602: 熟悉题型——类设计( 矩形类定义【C++】)
2602: 熟悉题型--类设计( 矩形类定义[C++]) 时间限制: 1 Sec 内存限制: 128 MB 提交: 183 解决: 119 题目描述 定义一个矩形类,数据成员包括左下角和右上角坐标 ...
- YTU 2987: 调整表中元素顺序(线性表)
2987: 调整表中元素顺序(线性表) 时间限制: 1 Sec 内存限制: 2 MB 提交: 1 解决: 1 题目描述 若一个线性表L采用顺序存储结构存储,其中所有元素都为整数.设计一个算法,将所 ...
- 删除线性表中所有值为x的元素
时间复杂度O(n),空间复杂度O(1). 简单的问题两种不同的思路. 代码: #include <stdio.h> #define MAX 100 struct sqlist{ int d ...
- C语言数据结构-顺序线性表的实现-初始化、销毁、长度、查找、前驱、后继、插入、删除、显示操作
1.数据结构-顺序线性表的实现-C语言 #define MAXSIZE 100 //结构体定义 typedef struct { int *elem; //基地址 int length; //结构体当 ...
- C语言 线性表 顺序表结构 实现
一个能够自动扩容的顺序表 ArrList (GCC编译). #include <stdio.h> #include <stdlib.h> #include <string ...
随机推荐
- BZOJ1565 植物大战僵尸
AC通道:http://www.lydsy.com/JudgeOnline/problem.php?id=1565 这题看上去并不会做,结果又是最大权闭合子图的裸题. 于是就去看了一发论文,明白建图的 ...
- Poj 2349 Arctic Network 分类: Brush Mode 2014-07-20 09:31 93人阅读 评论(0) 收藏
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9557 Accepted: 3187 De ...
- [工作积累] android 中添加libssl和libcurl
1. libssl https://github.com/guardianproject/openssl-android 然后执行ndk-build 2.libcurl 源代码组织结构, 下面的mak ...
- Goolg Chrome 插件开发--Hello world
开发Chrome插件很简单,只要会web开发(html+javascript+css)那么这个就是能驾轻就熟,只需要了解一下插件具体的运行环境及要求就OK了. 1.先创建一个html文件,名字随便取, ...
- Unity3d之音效播放和调用手机震动
http://blog.csdn.net/sunshine_1984/article/details/12943979 今天研究了下Unity3d音效播放相关内容,整理下实现细节. 1,添加音效文件到 ...
- iOS富文本-NSAttributedString简单封装
直接调用系统的写起来比较麻烦,封装一下 因为要简单所以就写类方法 WJAttributeStyle 基类 ) { ; i < styles.count; i ++) { ...
- java基础知识回顾之接口
/* abstract class AbsDemo { abstract void show1(); abstract void show2(); } 当一个抽象类中的方法都是抽象的时候,这时可以将该 ...
- C#反射技术的相关使用方法
1.获取同一程序集的类型实例 无参数构造函数 Type t=Type.GetType("AppCode.Employee"); object emp=t.Assembly.Crea ...
- hdu 4764 Stone (巴什博弈,披着狼皮的羊,小样,以为换了身皮就不认识啦)
今天(2013/9/28)长春站,最后一场网络赛! 3~5分钟后有队伍率先发现伪装了的签到题(博弈) 思路: 与取石头的巴什博弈对比 题目要求第一个人取数字在[1,k]间的某数x,后手取x加[1,k] ...
- ffplay 中filter的使用
添加字幕:ffplay -vf drawtext="fontfile=arial.ttf: text='Test Text': x=100: y=300: \ fontsize=48: fo ...