YTU-OJ-熟悉题型——填空题(删除线性表节点)
来源:互联网 发布:佳能手机打印软件 编辑:程序博客网 时间:2024/05/01 10:40
Problem N: 熟悉题型——填空题(删除线性表节点)
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 258 Solved: 151
[Submit][Status][Web Board]
Description
给出一串具体长度的数据,删除指定数据。
已经给出部分代码,
#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;
}
Input
输入 n:6
输入数据:1 2 3 4 5 6
输入 item:5
Output
输出:1 2 3 4 6
Sample Input
101 2 3 4 5 6 7 8 9 108
Sample Output
1 2 3 4 5 6 7 9 10
HINT
只提交注释的部分,即填写的部分。
填写的部分可能不止一行,根据自己的判断添加。
填空题添加的代码一般很短。
#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; } //begin if(p1->num==num) { if(p1==head) head=p1->next; else p2->next=p1->next; } //end 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-OJ-熟悉题型——填空题(删除线性表节点)
- YTU 2601: 熟悉题型——填空题(删除线性表节点)
- OJ 嘻唰唰:熟悉题型——填空题(删除线性表节点)
- OJ第三批——Problem N: 熟悉题型——填空题(删除线性表节点)
- YTU-OJ-Problem J: 熟悉题型——改错题(商品销售)
- YTU-OJ-Problem I: 熟悉题型——类设计( 矩形类定义【C++】)
- YTU-OJ-Problem L: 熟悉题型——自由设计(比较大小-类模板)
- OJ嘻唰唰之填空题(1)删除线性表节点
- YTU-OJ-Problem K: 熟悉题型——代码完善(输出日期时间--友元函数)
- YTU 2602: 熟悉题型——类设计( 矩形类定义【C++】)
- YTU 2605: 熟悉题型——自由设计(比较大小-类模板)
- YTU-OJ-Problem A: 最小节点(线性表)
- 2603: 熟悉题型——改错题(商品销售)
- YTU 2579: 填空题----删除指定字符
- YTU 2991: 链表节点逆置(线性表)
- YTU 2203: 最小节点(线性表)
- YTU 2986: 删除区间内的元素(线性表)
- YTU-OJ-单链表(线性表)-合并两个升序链表后降序输出
- C++为什么不加入垃圾回收机制
- Lua学习一
- 【CUDA并行编程之六】KNN算法的并行实现
- YTU-OJ-虚基类练习:动物
- 浅析在网页设计中如何让按钮激发用户点击欲望
- YTU-OJ-熟悉题型——填空题(删除线性表节点)
- iOS UI Label控件
- 打印样式
- YTU-OJ-C++时间类的运算符重载
- 求质数
- Intent.FLAG_ACTIVITY_CLEAR_TOP 的使用注意
- ubuntu 12.04 编译LTIB错误 Died at ./ltib line 1392.
- 【CUDA并行编程之七】数组元素之和
- [转]Rest架构成熟度