实现代码如下:
#include
#include
#include
#define MAX_SIZE 1000
#define SUCCESS 1
#define FAILURE 0
typedef int Status;
typedef int ElementType;
typedef struct SeqList {
ElementType data[MAX_SIZE];
int size;
} *SeqListPtr;
SeqListPtr CreateSeqList() {
SeqListPtr list = (struct SeqList *)malloc(sizeof(struct SeqList));
list->size = 0;
return list;
}
Status InsertElement(SeqListPtr list, int index, ElementType element) {
if (list->size == MAX_SIZE || index <1 || index > list->size + 1) {
return FAILURE;
}
if (index <= list->size) {
for (int i = list->size - 1; i >= index - 1; i--) {
list->data[i + 1] = list->data[i];
}
}
list->data[index - 1] = element;
list->size++;
return SUCCESS;
}
Status DeleteElement(SeqListPtr list, int index) {
if (list->size == 0 || index <1 || index > list->size) {
return FAILURE;
}
if (index size) {
for (int i = index; i size; i++) {
list->data[i - 1] = list->data[i];
}
}
list->size--;
return SUCCESS;
}
void RemoveInRange(SeqListPtr list, int start, int end) {
for (int i = 0; i size; i++) {
if (list->data[i] >= start && list->data[i] <= end) {
DeleteElement(list, i + 1);
i--;
}
}
}
Status PrintList(SeqListPtr list) {
for (int i = 0; i size - 1; i++) {
printf("%d ", list->data[i]);
}
printf("%d\n", list->data[list->size - 1]);
return SUCCESS;
}
int main() {
SeqListPtr list = CreateSeqList();
int numElements, start, end, element;
scanf("%d", &numElements);
for (int i = 1; i <= numElements; i++) {
scanf("%d", &element);
InsertElement(list, i, element);
}
scanf("%d %d", &start, &end);
RemoveInRange(list, start, end);
PrintList(list);
return 0;
}