-
若一个线性表L采用顺序存储结构存储,其中所有的元素为整数。设计一个算法,删除元素值在[x,y]之间的所有元素,要求算法的时间复杂度为O(n),空间复杂度为O(1)。
输入格式:
三行数据,第一行是顺序表的元素个数,第二行是顺序表的元素,第三行是x和y。
输出格式:
删除元素值在[x,y]之间的所有元素后的顺序表。
输入样例:
10
5 1 9 10 67 12 8 33 6 2
3 10输出样例:
1 67 12 33 2
-
#include <stdio.h>
#include <stdlib.h>#define MAXSIZE 100
typedef struct{
int a[MAXSIZE];
int length;
}SqList;int main()
{
SqList L;
L.length = 0;
int N,min,max,i,k;
scanf("%d",&N);
while(N--){
scanf("%d",&L.a[L.length]);
L.length++;
}
scanf("%d%d",&min,&max);
for(i = 0;i < L.length;i++){
if(L.a[i] >= min && L.a[i] <= max){
continue;
}
printf("%d ",L.a[i]);
}
return 0;
}
jmu-ds-顺序表区间元素删除(方法一)
最新推荐文章于 2023-09-08 16:44:47 发布