链表-删除指定元素
2015-11-12 09:12
429 查看
链表-删除指定元素
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
对于一个给定的线性表,要求删除线性表内的大于等于 min 且小于等于 max 的数,并输出删除后的线性表要求:必须使用链表做,否则不计成绩!
输入
输入的第一行为一个正整数 T,表示有 T 组测试数据。每组测试数据的第一行为三个整数n、min、max,表示有 n 个数据,删除的范围为[min, max].第二行为 n 个整数代表初始的 n 个数据。
输出
输出删除数据后的线性表,如果线性表为空则输出-1示例输入
2 3 1 2 1 2 3 5 2 1 1 1 1 1 1
示例输出
3 1 1 1 1 1
提示
来源
gaoyongxin示例程序
#include<stdio.h> #include<stdlib.h> struct node { int data; struct node *next; }; struct node * inset(struct node *head,int n) { int i; struct node *p,*q,*tail; q=head; for(i=0;i<n;i++) { p=(struct node *)malloc(sizeof(struct node)); scanf("%d",&p->data); p->next=q->next; q->next=p; q=p; } return(head); } int main() { int i,j,n,m,a,b,c,k; struct node *head,*p,*q,*tail; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d %d %d",&m,&a,&b); head=(struct node *)malloc(sizeof(struct node)); head->next=NULL; head=inset(head,m); q=head; while(q->next!=NULL) { k=1; if((q->next->data>=a)&&(q->next->data<=b)) { k=0; p=q->next; q->next=p->next; free(p); } if(k!=0) q=q->next; } p=head; p=p->next; if(p==NULL) { free(head); printf("-1"); } else while(p!=NULL) { q=p; printf("%d ",p->data); p=p->next; free(q); } printf("\n"); } }
相关文章推荐
- 《剑指offer》——数组中的逆序对
- C#中public、private、protected、internal、protected internal (转载)
- 子串
- fopen与open的区别
- IOS开发网络篇之──ASIHTTPRequest详解
- Array运用
- Script Send triggle mail for zabbix
- 谷歌开源人工智能系统 TensorFlow
- 素数
- Save a File on External Storage
- IIS 6文件解析漏洞
- WebViewJavascriptBridge-Obj-C和JavaScript互通消息的桥梁
- c语言的头文件-不是c++类的头文件?
- 【Unity实用小方法】随机生成不重复的数字
- AD DS功能浅析--AD DS概述
- Linux下如何查看tomcat是否启动/系统日志等
- JNI:JAVA调用C库方法
- TCP/IP
- 新版QQ登录Canvas闪动特效
- Android WebView打开https地址错误的问题