# 删除区间内的元素（线性表）

typedef struct
{
ElemType data[SizeMax];
int length;
} SqList;

bool Delete(SqList *&L,ElemType x,ElemType y);

### 注意：只需提交删除区间内元素的算法Delete部分。

``````10
5 3 6 2 1 9 8 7 4 0
3 7``````

``````5
2 1 9 8 0``````

``````#include <iostream>

#define SizeMax 30

using namespace std;

struct SqList{
int data[SizeMax];
int length;
};

bool Delete(SqList *&L,int x,int y){
/*if(x<-2147483648||y>2147483647){
return false;
}*/
int i=0;
while(i<L->length){
if(L->data[i]>=x&&L->data[i]<=y){
for(int j=i;j<L->length;j++){
L->data[j]=L->data[j+1];
}
L->length--;
}else{
i++;
}
}
return true;
}

int main()
{
int num,x,y;
struct SqList *sl=new SqList;
cin>>num;
sl->length=num;
for(int i=0;i<num;i++){
cin>>sl->data[i];
}
cin>>x>>y;
Delete(sl,x,y);
for(int i=0;i<sl->length;i++){
cout<<sl->data[i]<<" ";
}
cout<<endl;
delete sl;
return 0;
}
``````

``````
#include <stdio.h>
#include <stdlib.h>
#define SizeMax 10000
typedef int ElemType;
typedef struct
{
ElemType data[SizeMax];
int length;
} SqList;
void CreateList(SqList *&L,ElemType n)
{
if(n>SizeMax)return;
L=(SqList*)malloc(sizeof(SqList));
for(int i=0; i<n; i++)
scanf("%d",&L->data[i]);
L->length=n;
}bool Delete(SqList *&L,int x,int y)
{
if(x>y)return false;
int n=L->length;
for(int i=0,j=0;i<n;i++)
{
if(L->data[i]>=x&&L->data[i]<=y)L->length--;
else L->data[j++]=L->data[i];
}
return true;
}
void Print(SqList *L)
{
int i;
printf("%d\n",L->length);
for(i=0; i<L->length; i++)
printf(i!=L->length-1?"%d ":"%d\n",L->data[i]);
}
void DestroyList(SqList *&L)
{
free(L);
}
int main()
{
SqList *L;
ElemType n,x,y;
scanf("%d",&n);
CreateList(L,n);
scanf("%d%d",&x,&y);
if(Delete(L,x,y))
Print(L);
DestroyList(L);
return 0;
}
``````