zoukankan      html  css  js  c++  java
  • 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;
    }
    

  • 相关阅读:
    语音信号端点检测
    WEBPACK & BABEL 打包项目
    使用 Qt 获取 UDP 数据并显示成图片(2)
    QSS为Qt程序添加不一样的样式
    window 搜索大文件
    Idea java 编译发生 cannot find symbol
    JetBeans Tab键相关设置
    JetBean Rider 重命名 c# 程序集名
    Unity 导入其他工程
    列出当前文件夹下的以log结尾的文件名
  • 原文地址:https://www.cnblogs.com/im0qianqian/p/5989534.html
Copyright © 2011-2022 走看看