//删除区间内元素
#include<iostream>
using namespace std;
typedef struct lnode {
int data;
struct lnode* next;
}lnode,*linklist;
int a[7] = { 11,22,67,44,67,99,87 };
int n = 7;
void buildlist(linklist& L)
{
L = (lnode*)malloc(sizeof(lnode));
if (L == NULL)return;
lnode* s, * r = L;
for (int i = 0; i < n; i++)
{
s = (lnode*)malloc(sizeof(lnode));
s->data = a[i];
r->next = s;
r = r->next;
}
r->next = NULL;
}
void disp(linklist L)
{
lnode* s = L->next;
while (s) {
cout << s->data << " ";
s = s->next;
}
cout << endl;
}
void deletexy(linklist& L, int x, int y)
{
if (L == NULL)return;
lnode* p = L->next, * r = L, * q;
while (p)
{
if (p->data<y && p->data>x)
{
q = p;
p = p->next;
r->next = q->next;
free(q);
}
else {
r = p;
p = p->next;
}
}
}
int main()
{
linklist L;
buildlist(L);
disp(L);
deletexy(L, 20, 80);
disp(L);
return 0;
}