单链表删除某区间的值
来源:互联网 发布:vue.js html模板 编辑:程序博客网 时间:2024/05/29 08:56
#include <iostream>//#include"head.h"#include<string.h>using namespace std;struct node{ int data; node* next;};node* head;int len;void creat(){ head=NULL; node* r=NULL; int x; for(int i=0;i<len;i++) { cin>>x; node* p=new node; p->data=x; if(head==NULL) { head=p; } else { r->next=p; } r=p; } r->next=NULL; node* newhead=new node; newhead->next=head; head=newhead;}int remove( const int& left, const int& right ){ node* cur=head->next; node* pre=head; int count=0; while(cur) { if(cur->data>=left&&cur->data<=right) { count++; node* q=cur; pre->next=cur->next; cur=cur->next; delete q; } else{ pre=cur; cur=cur->next; } } return count;}void show_all(){ node* p=head->next; while(p) { cout<<p->data; if(p->next) cout<<' '; p=p->next; } cout<<endl;}void discard(){ node* p=head->next; while(p) { node* q=p; p=p->next; delete q; }}int main(){ int T ; cin>>T; while(T--) { int left; int right; cin>>left>>right>>len; creat(); int ret=remove(left,right); if(ret!=len) { cout<<len-ret<<endl; show_all(); discard(); } } return 0;}
阅读全文
0 0
- 单链表删除某区间的值
- 对最后修改日期在某区间内的INFO-RECORD做删除标记
- 对某区间的cell进行操作
- 某区间内1的数量
- python输出某区间内的素数
- 某区间内1的数量
- 询问某区间内有多少满足某个要求的/某区间以某式子计算出的值(莫队算法,不修改只询问区间)
- 求某区间内的素数(试除法)
- Random使用和生成某区间的随机数
- 统计某区间内的素数并打印显示
- UVA 3883 某区间的素数 【素数筛法】
- 让某区域的按钮失效
- python生成某区间内不重复的随机数
- 桶排序:某区间内排序
- 查询某区间内最靠右的不超过k的数
- 06多次查询某区间内topk问题
- 【HTML】使用Iframe标签显示目标网页(内容)的某区域
- Iframe标签显示目标网页中某区域内容的实现方法
- php获取指定日期时间
- Request作为域对象存取数据 Request作为域对象;请求转发和重定向都可以完成页面跳转
- 7-62 切分表达式——写个tokenizer吧
- 利用Ajax实现数据的同步传输,从mysql中提取数据,通过echarts可视化
- PHP学习笔记 06
- 单链表删除某区间的值
- 创建和删除文档需要手动刷新显示的问题
- websphere jms配置
- Python的http请求
- 请求转发和重定向区别 请求转发和重定向原理:
- MySQL常用语句
- 评分卡的建立方法——分箱、WOE、IV、分值分配
- JSP之自己构建WEB应用
- Android脱壳圣战之---脱掉360加固壳(破解约火包神器的钻石充值功能)