#include<stdio.h>
#include<stdlib.h>
#define ElemType int
#define MaxSize 10
#define true 1
#define false 0
typedef int bool;
typedef struct {
ElemType data[MaxSize];
int length;
}SqList;
void InitList(SqList *L) {
L->length = 0;
}
void PrintList(SqList L) {
for (int i = 0; i < L.length; i++) {
printf("%d ", L.data[i]);
}
printf("\n");
}
bool ListInsert(SqList *L,int index,ElemType e) {
if (index<1 || index>L->length+1) {
return false;
}
for (int i = L->length; i >= index; i--) {
L->data[i] = L->data[i - 1];
}
L->data[index - 1] = e;
L->length++;
return true;
}
bool ListDelete(SqList* L, int index, ElemType *e) {
if (index<1 || index>L->length) {
return false;
}
*e = L->data[index - 1];
for (int i = index; i < L->length; i++) {
L->data[i - 1] = L->data[i];
}
L->length--;
return true;
}
bool GetElem(SqList L,int index,int* e) {
if (index<1 || index>L.length) {
return false;
}
*e = L.data[index - 1];
return true;
}
bool LocateElem(SqList L,int e,int* index) {
for (int i = 0; i < L.length; i++) {
if (e == L.data[i]) {
*index = i+1;
return true;
}
}
return false;
}
bool ModifyElem(SqList *L,int index,int e) {
if (index<1 || index>L->length) {
return false;
}
L->data[index - 1] = e;
return true;
}
int main() {
SqList L;
InitList(&L);
L.length = 6;
for (int i = 0; i < 6; i++) {
L.data[i] = 0;
}
ListInsert(&L, 3, 9);
PrintList(L);
ElemType e;
ListDelete(&L, 6, &e);
PrintList(L);
ModifyElem(&L, 3, 12);
PrintList(L);
return 0;
}