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. discuz之同步登入

    前言   首先感谢dozer学长吧UCenter翻译成C# 博客地址----------->http://www.dozer.cc/   其次感谢群友快乐々止境同学的热心指导,虽然萍水相逢但让我 ...

  2. DOM操作样式表及其兼容性

    DOM操作样式表的时候,存在很多浏览器兼容上的问题,测试的时候用的是Firefox 28.0.IE11.IE8.Chrome.测试的时候发现,不兼容问题基本上都是IE8和非IE浏览器之家的问题,很多I ...

  3. Leetcode#73 Set Matrix Zeroes

    原题地址 用矩形的第一行和第一列充当mask 代码: void setZeroes(vector<vector<int> > &matrix) { ].empty()) ...

  4. 网络(一),libevent客户端部分

    网络模块() 一.服务端: 暂时就以libevent模块,共享内存等下 .GS打开,首先创建4个libevent子线程,当然为每个线程设置连接通知回调函数,这个是基于sockpair的,然后再创建一个 ...

  5. Codeforces Round #364 (Div. 2)->A. Cards

    A. Cards time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

  6. HDU1014Uniform Generator

    Uniform Generator Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   ...

  7. [geeksforgeeks] Lowest Common Ancestor in a Binary Search Tree.

    http://www.geeksforgeeks.org/lowest-common-ancestor-in-a-binary-search-tree/ Lowest Common Ancestor ...

  8. unity3d 自动保存

    using UnityEngine; using UnityEditor; using System; public class AutoSave : EditorWindow { private b ...

  9. POJ3525 Most Distant Point from the Sea(半平面交)

    给你一个凸多边形,问在里面距离凸边形最远的点. 方法就是二分这个距离,然后将对应的半平面沿着法向平移这个距离,然后判断是否交集为空,为空说明这个距离太大了,否则太小了,二分即可. #pragma wa ...

  10. POJ 1325

    #include<iostream> #include<stdio.h> #define MAXN 105 using namespace std; int _m[MAXN][ ...