#include <stdio.h>
#include <stdlib.h>
#define N 5
typedef struct list
{
int data;
struct list *next;
}LNode;
LNode *creatlist(int *a)
{
LNode *h,*p,*q;
int i;
h=p=(LNode *)malloc(sizeof(LNode));
for(i=0; i<N; i++)
{
q=(LNode *)malloc(sizeof(LNode));
q->data=a[i];
p->next=q;
p=q;
}
p->next=0;
return h;
}
void outlist(LNode *h)
{
LNode *p;
p=h->next;
if (p==NULL)
printf("\nThe list is NULL!\n");
else
{
printf("\nHead");
do {
printf("->%d",p->data);
p=p->next;
} while(p!=NULL);
printf("->End\n");
}
}
void delet(LNode *L, int mink, int maxk)
{
LNode *p,*pre,*q,*s;
p=L->next;
while (p&&p->data<=mink)
{
pre=p;
p=p->next;
}
if(p)
{
while(p&&p->data<maxk)
{
p=p->next;
}
q=pre->next;
pre->next=p;
while (q!=p)
{
s=q->next;
free(q);
q=s;
}
}
}
int main( )
{
LNode *A;
int n=2,m=8;
int a[N]={1,2,3,5,9};
A=creatlist(a);
outlist(A);
delet(A,n,m);
outlist(A);
return 0;
}