链表-删除指定元素 SDUT 1464
2014-03-25 23:04
232 查看
#include <stdio.h> #include <stdlib.h> #include <malloc.h> #include <string.h> struct node { int data; struct node *next; }; int main() { int n,i,min,max,t; scanf("%d",&t); while(t--) { struct node *head,*tail,*p,*a,*b; head=(struct node *)malloc(sizeof(struct node)); head->next=NULL; tail=head; scanf("%d%d%d",&n,&min,&max); for(i=1;i<=n;i++) { p=(struct node *)malloc(sizeof(struct node)); p->next=NULL; scanf("%d",&p->data); tail->next=p; tail=p; } a=head; b=head->next; while(b) { if(b->data>=min && b->data<=max) { a->next=b->next; free(b); b=a->next; } else { a=a->next; b=b->next; } } if(head->next==NULL) printf("-1\n"); else { while(head->next->next) { printf("%d ",head->next->data); head=head->next; } printf("%d\n",head->next->data); } } return 0; }
相关文章推荐
- SDUT_OJ_1464-链表-删除指定元素
- 数据结构实验之链表七:单链表中重复元素的删除 (SDUT 2122)
- C++单链表中删除指定范围内的元素
- 删除链表中指定元素
- 创建一个链表,插入删除,指定元素
- C++单链表中删除指定范围内的元素
- Remove Linked List Elements 删除链表中指定元素
- 删除链表中指定的所有元素
- C++单链表中删除指定范围内的元素
- lintcode:删除链表中指定元素
- 删除链表中指定位置的元素
- 【链表面试题】删除无头单链表的非尾节点,插入一个元素到无头链表指定位置
- C++单链表中删除指定范围内的元素
- 【链表面试题】删除无头单链表的非尾节点,插入一个元素到无头链表指定位置
- SDUT 2122 数据结构实验之链表七:单链表中重复元素的删除
- C++单链表中删除指定范围内的元素
- 删除链表中指定的元素
- SDUT-2122 数据结构实验之链表七:单链表中重复元素的删除
- C++单链表中删除指定范围内的元素
- 链表的基本操作(创建,查找指定位置元素,删除指定元素,插入,倒置,去重,求集合的差,分别交换结点与交换结点值实现的冒泡排序,将两个有序链表合并成一个有序链表)c语言实现