2.4 试编写算法,从有序表中删除其值在给定值s和t(s<t)之间的所有元素
由于题目没有额外要求,代码就没有判断是否为空的顺序表~
#include<iostream>
#define MaxSize 100
using namespace std;
int s,t;
struct SqList
{
int a[MaxSize];
int len;
};
void Del(SqList *L,int s,int t){
int i=0,j=0;
while (i<L->len)
{
if(L->a[i]>=s&&L->a[i]<=t) i++;
else{
L->a[j]=L->a[i];
i++;
j++;
}
}
L->len=j;
}
int main()
{
cin>>s>>t;
SqList *L; L->len=80;
for(int i=0;i<L->len;i++) L->a[i]=(i+2)%5;
Del(L,s,t);
for(int i=0;i<L->len;i++) cout<<L->a[i]<<" ";
return 0;
}