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;
}

YTU 2601: 熟悉题型——填空题(删除线性表节点)的更多相关文章

  1. YTU 2579: 填空题----删除指定字符

    2579: 填空题----删除指定字符 时间限制: 1 Sec  内存限制: 128 MB 提交: 164  解决: 61 题目描述 小明想要做个小程序,能够删除字符串中特定的字符. 例如:想要在下面 ...

  2. 删除线性表中为x的元素的三种简单算法。

    //删除线性表中不为x的元素. void delete_list(Sqlist &L,int x){ ; ;i < L.length;i++){ if(L.data[i] != x){ ...

  3. YTU 2607: A代码填空题--更换火车头

    2607: A代码填空题--更换火车头 时间限制: 1 Sec  内存限制: 128 MB 提交: 91  解决: 73 题目描述 注:本题只需要提交填写部分的代码,请按照C++方式提交. 假设火车有 ...

  4. YTU 2605: 熟悉题型——自由设计(比较大小-类模板)

    2605: 熟悉题型--自由设计(比较大小-类模板) 时间限制: 1 Sec  内存限制: 128 MB 提交: 125  解决: 107 题目描述 声明一个类模板,利用它分别实现两个整数.浮点数和字 ...

  5. YTU 2602: 熟悉题型——类设计( 矩形类定义【C++】)

    2602: 熟悉题型--类设计( 矩形类定义[C++]) 时间限制: 1 Sec  内存限制: 128 MB 提交: 183  解决: 119 题目描述 定义一个矩形类,数据成员包括左下角和右上角坐标 ...

  6. YTU 2987: 调整表中元素顺序(线性表)

    2987: 调整表中元素顺序(线性表) 时间限制: 1 Sec  内存限制: 2 MB 提交: 1  解决: 1 题目描述 若一个线性表L采用顺序存储结构存储,其中所有元素都为整数.设计一个算法,将所 ...

  7. 删除线性表中所有值为x的元素

    时间复杂度O(n),空间复杂度O(1). 简单的问题两种不同的思路. 代码: #include <stdio.h> #define MAX 100 struct sqlist{ int d ...

  8. C语言数据结构-顺序线性表的实现-初始化、销毁、长度、查找、前驱、后继、插入、删除、显示操作

    1.数据结构-顺序线性表的实现-C语言 #define MAXSIZE 100 //结构体定义 typedef struct { int *elem; //基地址 int length; //结构体当 ...

  9. C语言 线性表 顺序表结构 实现

    一个能够自动扩容的顺序表 ArrList (GCC编译). #include <stdio.h> #include <stdlib.h> #include <string ...

随机推荐

  1. Codeforces Round #354 (Div. 2) D. Theseus and labyrinth

    题目链接: http://codeforces.com/contest/676/problem/D 题意: 如果两个相邻的格子都有对应朝向的门,则可以从一个格子到另一个格子,给你初始坐标xt,yt,终 ...

  2. NYOJ-949 哈利波特 AC 分类: NYOJ 2013-12-30 12:57 217人阅读 评论(0) 收藏

    #include<stdio.h> int main(){ long long a,b,c,d,e,f; while(scanf("%lld%lld%lld%lld%lld%ll ...

  3. [错误代码:0x80070002]IIS7及以上伪静态报错404

    故障现象:DTCMS开启伪静态功能,VS2010预览正常,发布到IIS后报错404.0错误 (WIN7,WIN8,SERVER2008).模块IISWebCore通知MapRequestHandler ...

  4. c++ assert

    #include<iostream> #include <assert.h> using namespace std; int main() { ; assert(a == ) ...

  5. 使用Provider时提示:Unable to get provider...

    具体原因还不清楚,只是找到了原因: 这是因为自定义的Provider放的包路径不对,自定义的Provider应该放到和MainActivity同一个包中.

  6. HDU4542 小明系列故事——未知剩余系

    大赞的数论题: 大致思路: 对于TYPE=1的情况,认为 X 中有 X-K个约数,求最小的X,X-K>0 那么化为B+K的约数为B, 我们知道(B+K)的约数<=2*SQRT(B+K);这 ...

  7. Unity Texture 2D Compress

    测试了一下 unity 图片 对 apk 的影响. 上两种测试环境    1024 * 1024     带 alpha的话 默认压缩就是RBA 16bit就是2M     不带的话就是 etc 的话 ...

  8. PHP7安装笔记

    PHP7安装笔记 时间 -- :: 喵了个咪 原文 http://www.hdj.me/php7-install-note 主题 PHP # 安装mcrypt yum install -y php-m ...

  9. js获取服务器时间

    Ajax HTTP Head法原理:一般服务器在发送静态页面的时候(apache, nginx, lighttpd就目前所知)都是会在 HTTP 头里带一个Date的头信息的,那么我用Ajax直接取头 ...

  10. 压测2.0:云压测 + APM = 端到端压测解决方案

    从压力测试说起 压力测试是确立系统稳定性的一种测试方法,通常在系统正常运作范围之外进行,以考察其功能极限和隐患.与功能测试不同,压测是以软件响应速度为测试目标的,尤其是针对在较短时间内大量并发用户的访 ...