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 ...
随机推荐
- proxy server 代理服务器
有时候,我觉得自己需要去搞明白.搞清楚一个概念,帮我打通一下自己的知识体系,或者说,尝试联络起来. 1. 简介 突破自身IP限制,访问国外站点. 访问单位或者团体内部资源. 突破中国电信的IP封锁. ...
- 资料共享平台----nabcd
知识共享平台NABCD模型 N(need)需求 大一新生刚刚开始大学生活,不适应大学学习生活的节奏,并且课堂上知识容量大.密度高,学生不能立刻掌握所学知识点,同时,网上资料冗杂繁复,指向性不强,导致学 ...
- 请实现一个函数用来判断字符串是否表示数值(包括整数和小数)。例如,字符串"+100","5e2","-123","3.1416"和"-1E-16"都表示数值。 但是"12e","1a3.14","1.2.3","+-5"和"12e+4.3"都不是。
// test20.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include< ...
- 在C++的类中,普通成员函数不能作为pthread_create的线程函数,如果要作为pthread_create中的线程函数,必须是static
在C++的类中,普通成员函数不能作为pthread_create的线程函数,如果要作为pthread_create中的线程函数,必须是static ! 在C语言中,我们使用pthread_create ...
- ASP.NET防止用户多次登录的方法
常见的处理方法是,在用户登录时,判断此用户是否已经在Application中存在,如果存在就报错,不存在的话就加到Application中(Application是所有Session共有的,整个web ...
- 数据库表 copy
db1为原数据库,db2为要导出到的数据库,fromtable 是要导出的表名 1.方法一:登录导出到的数据库,执行create table fromtable select * from db1.f ...
- ZOJ3231 Apple Transportation(最小费用流)
题目给你一棵苹果树,然后每个结点上有一定的苹果树,你要将苹果运输达到某个状态,使得均方差最小. 将苹果x个从a->b的花费是x*w,w是边权. 当时比赛的时候想的就是,最后达到的状态一定是sum ...
- 为jquery qrcode生成的二维码嵌入图片
在一次微信项目中,需要实现通过扫描二维码来进行会议签到,二维码的生成选择了qrcode.js的版本,然后使用jquery.qrcode.js插件来绘制二维码. <script type=&quo ...
- (转)Android: NDK编程入门笔记
转自: http://www.cnblogs.com/hibraincol/archive/2011/05/30/2063847.html 为何要用到NDK? 概括来说主要分为以下几种情况: 1. 代 ...
- BZOJ 1296: [SCOI2009]粉刷匠 分组DP
1296: [SCOI2009]粉刷匠 Description windy有 N 条木板需要被粉刷. 每条木板被分为 M 个格子. 每个格子要被刷成红色或蓝色. windy每次粉刷,只能选择一条木板上 ...