链表——删除指定元素
来源:互联网 发布:静脉注射空气 知乎 编辑:程序博客网 时间:2024/06/05 22:37
链表-删除指定元素
Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic Discuss
Problem Description
对于一个给定的线性表,要求删除线性表内的大于等于 min 且小于等于 max 的数,并输出删除后的线性表
要求:必须使用链表做,否则不计成绩!
要求:必须使用链表做,否则不计成绩!
Input
输入的第一行为一个正整数 T,表示有 T 组测试数据。
每组测试数据的第一行为三个整数n、min、max,表示有 n 个数据,删除的范围为[min, max].第二行为 n 个整数代表初始的 n 个数据。
Output
输出删除数据后的线性表,如果线性表为空则输出-1
Example Input
23 1 21 2 35 2 11 1 1 1 1
Example Output
31 1 1 1 1
Hint
Author
gaoyongxin
#include<iostream>#include<stdio.h>using namespace std;struct Lnode{ int data; Lnode * next;};Lnode * del(Lnode * head,int a, int b){ Lnode * tail; tail=head; while(head->next) { if(head->next->data>=a && head->next->data<=b) { head->next=head->next->next; } else head=head->next; } return tail;}int main(){ int t; int n,min,max; cin>>t; while(t--) { cin>>n>>min>>max; Lnode * head, * tail , * liste; head=new Lnode; head->data=0; head->next=NULL; tail=head; while(n--) { int a; cin>>a; liste=new Lnode; liste->data=a; liste->next=NULL; tail->next=liste; tail=liste; } head=del(head,min,max); if(head->next==NULL) { cout<<"-1"<<endl; } else { head=head->next; while(head->next) { cout<<head->data<<" "; head=head->next; } cout<<head->data<<endl; } }}
0 0
- 链表——删除指定元素
- 链表-删除指定元素
- SDUT_OJ_1464-链表-删除指定元素
- LeetCode 分类练习(1)—— 在数组中移动指定元素、删除指定元素、删除重复元素
- 提高篇——删除指定位置上的元素
- 链表-删除指定元素 SDUT 1464
- sdut oj1464 链表-删除指定元素
- List 删除指定元素
- 删除数组指定元素
- ArrayList删除指定元素
- map 删除指定元素
- Vector删除指定元素
- vector删除指定元素
- Vector删除指定元素
- 删除单链表指定元素
- 删除指定元素
- STL删除指定元素
- vector删除指定元素
- 程序员的自我修养——2、编译和链接
- Java多线程生产者消费者问题
- minicom and kermit
- struts解压后的各个文件夹的作用
- Ubuntu14.04下Python集成开发环境Anaconda安装配置
- 链表——删除指定元素
- 原码反码补码和python中的按位运算易混点
- 关系型数据库和非关系型数据库的特性以及各自的优缺点
- javascript编译器的一些原理——变量提升
- 技术人的充电时刻,24个精彩研发案例在等你
- MFC中将一个Button控件失效的方法
- 如何转载别人的csdn博客
- java应届生面试总结
- hdu 3037 Saving Beans (卢卡斯定理)