#请问这段代码为什么实现不了删除有序表中在s到t之间的值,运行代码没错,但是无法实现。
#include<iostream>
using namespace std;
#include<string>
#define Max 50
struct sqlist
{
int A[Max] = { 1,3,3,4,5,6,7,8,8,9 };
int length = 10;
};
bool Del(sqlist& l, int s, int t)
{
int i, j;
if (s >= t || l.length == 0)
return false;
for (i = 0; i < l.length && l.A[i] < s; i++)
if (i >= l.length)
return false;
for (j = i; j < l.length && l.A[j] <= t; j++)
for (; j < l.length; i++, j++)
l.A[i] = l.A[j];
l.length = i;
return true;
}
int main()
{
sqlist l;
for (int i = 0; i < l.length; i++)
cout << l.A[i] << " ";
cout << endl;
Del(l, 3, 8);
for (int j = 0; j < l.length; j++)
cout << l.A[j] << " ";
cout << endl;
return 0;
}