#include "stdio.h"
#include "stdlib.h"
#define null 0
typedef struct node//结点结构
{
int data;
struct node *next;
}LNode;
LNode *create()//创建单链表
{
LNode *head,*tail,*p;
int x;
head=(LNode *)malloc(sizeof (LNode));
head->next=null;
tail=head;
scanf("%d",&x);
while(x!=0)
{
p=(LNode *)malloc(sizeof(LNode));//申请结点
p->data=x;//填入数据
p->next=null;
tail->next=p;
tail=p;
scanf("%d",&x);
}
return head;
}
void Delete(LNode *head,int min,int max)//删除大于Min小于Max的元素
{
LNode *p,*q;
p=head;
while (p->next!=NULL)
{
if (p->next->data<max&&p->next->data>min)
{q=p->next;
p->next=p->next->next;//删除指定的字符
free(q);
}
else
p=p->next;//不删除,只是指针后移
}
}
void print(LNode *head)//打印单链表
{
LNode *p;
p=head->next;
while(p!=null)
{
printf("%3d",p->data);
p=p->next;
}
}
void main()
{
LNode *H;
int min,max;
printf("创建单链表:\n");
H=create();
printf("输入删除区间的上下限:\n");
scanf("%d\n,%d\n",&min,&max);
Delete(H,min,max);
printf("删除元素后的单链表为: \n");
print(H);
printf("\n");
}