链表——删除指定元素
2017-03-02 20:13
381 查看
链表-删除指定元素
Time Limit: 1000MS Memory Limit: 65536KBSubmit Statistic Discuss
Problem Description
对于一个给定的线性表,要求删除线性表内的大于等于 min 且小于等于 max 的数,并输出删除后的线性表要求:必须使用链表做,否则不计成绩!
Input
输入的第一行为一个正整数 T,表示有 T 组测试数据。每组测试数据的第一行为三个整数n、min、max,表示有 n 个数据,删除的范围为[min, max].第二行为 n 个整数代表初始的 n 个数据。
Output
输出删除数据后的线性表,如果线性表为空则输出-1
Example Input
2 3 1 2 1 2 3 5 2 1 1 1 1 1 1
Example Output
3 1 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; } } }
相关文章推荐
- 数据结构之 线性表---单链表操作A (删除链表中的指定元素)
- 删除链表中指定位置的元素
- C++单链表中删除指定范围内的元素
- C++单链表中删除指定范围内的元素
- C++单链表中删除指定范围内的元素
- SDUT_OJ_1464-链表-删除指定元素
- 在双向链表中删除指定元素
- C++单链表中删除指定范围内的元素
- 递归删除链表中的指定元素x
- C++单链表中删除指定范围内的元素
- 链表-删除指定元素
- 单链表的基本操作(尾插,尾删,头插,头删,查找,指定位置插入、删除,指定元素删除、全部删除等)
- sdut oj1464 链表-删除指定元素
- C++单链表中删除指定范围内的元素
- 链表-删除指定元素 SDUT 1464
- 删除链表中指定元素
- 删除链表中指定的所有元素
- 【链表面试题】删除无头单链表的非尾节点,插入一个元素到无头链表指定位置
- 删除链表中指定的元素
- C++单链表中删除指定范围内的元素