6-1 线性表元素的区间删除 (20分)
//特殊的情况之一就是一个都不用删除
List Delete( List L, ElementType minD, ElementType maxD )
{
int k = 0;
for (int j = 0; j <= L->Last; j++)
{
if (L->Data[j] <= minD || L->Data[j] >= maxD)
{
L->Data[k] = L->Data[j];
k++;
}
}
L->Last = k-1;
return L;
}
7-2 最长连续递增子序列 (20分)
//我不知道最大n是怎么过的
#include <iostream>
using namespace std;
typedef int ElemType;
typedef struct SqList
{
ElemType *elem;
int length;
}SqList;
int main()
{
SqList L;
cin >> L.length;
L.elem = (ElemType*)malloc(sizeof(ElemType) * L.length);
for (int i = 0; i < L.length; i++)
cin >> L.elem[i];
int max_start = 0, max_len = 1;
int cur_start = 0, cur_len = 1;
//这么写 在逻辑上比较顺畅
for (int i = 1; i < L.length; i++)
{
if (L.elem[i - 1] < L.elem[i])
cur_len ++;
else
{
if (cur_len > max_len)
{
max_start = cur_start;
max_len = cur_len;
}
cur_start = i;
cur_len = 1;
}
}
//若最后一部分序列还是递增,但没有结束
if (L.elem[L.length - 2] < L.elem[L.length - 1])
{
if (cur_len > max_len)
{
max_start = cur_start;
max_len = cur_len;
}
}
for (int i = 0; i < max_len; i++)
{
if (i) cout << ' ';
cout << L.elem[max_start + i];
}
cout << endl;
system("pause");
return 0;
}