![image.png](https://i-blog.csdnimg.cn/blog_migrate/ecbe6e7da3787f73847af62e9a4c5e19.png)
函数代码:
List Delete(List L, ElementType minD, ElementType maxD) {
List NewL = (List)malloc(sizeof(struct LNode));
int j = 0;
for (int i = 0; i <= L->Last; i++) {
if (L->Data[i] > minD && L->Data[i] < maxD) {
continue;
}
NewL->Data[j++] = L->Data[i];
}
NewL->Last = j - 1;
return NewL;
}
全部代码:
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 20
typedef int ElementType;
typedef int Position;
typedef struct LNode *List;
struct LNode {
ElementType Data[MAXSIZE];
Position Last;
};
List ReadInput();
void PrintList(List L);
List Delete(List L, ElementType minD, ElementType maxD);
int main()
{
List L;
ElementType minD, maxD;
int i;
L = ReadInput();
scanf("%d %d", &minD, &maxD);
L = Delete(L, minD, maxD);
PrintList(L);
return 0;
}
List ReadInput() {
List L = (List)malloc(sizeof(struct LNode));
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &(L->Data[i]));
}
L->Last = n - 1;
return L;
}
void PrintList(List L) {
for (int i = 0; i <= L->Last; i++) {
printf("%d ", L->Data[i]);
}
printf("\n");
}
List Delete(List L, ElementType minD, ElementType maxD) {
List NewL = (List)malloc(sizeof(struct LNode));
int j = 0;
for (int i = 0; i <= L->Last; i++) {
if (L->Data[i] > minD && L->Data[i] < maxD) {
continue;
}
NewL->Data[j++] = L->Data[i];
}
NewL->Last = j - 1;
return NewL;
}