#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
//从有序表中删除给定值在s到t之间的所有元素,st不合理或者表为空返回错误
const int N=100;
typedef struct
{
int data[N];
int n;//长度
}sqlist;
bool delete_s_t_(sqlist& L, int &n,int s,int t)
{
if (L.n == 0 || s >= t) return false;
int i, j;
int start, end;
for (i = 0;i<L.n&& L.data[i] < s; i++) start=i;
if (i >= L.n) return false;
for (int j = i; i < L.n && L.data[j] <= t; j++) end = j;
start++;
end++;
while (end < L.n)
{
L.data[start++] = L.data[end++];
}
L.n = start;
return true;
}
int main()
{
sqlist L;
cout << "链表长度?" << endl;
cin >> L.n;
for (int i = 0; i < L.n; i++)
{
cout << "请输入第" <<i+1<<"个元素的数值" <<endl;
cin >> L.data[i];
}
cout << "你要删除的元素范围是?" << endl;
int s, t;
cin >> s >> t;
cout << endl;
cout << "删除前的序列" << endl;
for (int i = 0; i < L.n; i++) cout << L.data[i] << ' ';
delete_s_t_(L, L.n, s,t);
cout << endl;
cout << "删除后的序列" << endl;
for (int i = 0; i < L.n; i++) cout << L.data[i]<<' ';
return 0;
}
08-06
239
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
11-12
433
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)