#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdbool.h>
#define MaxSize 50
typedef struct {
int data[MaxSize];
int length;
}SqList;
#define InitSize 100;
typedef struct {
int* data;
int Maxsize, Length;
}SeqList;
void init(SqList* L) {
L->length = 10;
for (int i = 0;i < L->length;i++) {
L->data[i] = i;
}
}
void MyPrint(SqList L) {
for (int i = 0;i < L.length;i++) {
printf("%d", L.data[i]);
}
}
bool ListInsert(SqList* L, int i, int e) {
if (i < 0 || i >= L->length) {
return false;
}
if (L->length == MaxSize) {
return false;
}
int j = 0;
for (j = L->length;j >= i;j--) {
L->data[j] = L->data[j-1];
}
L->data[j] = e;
L->length++;
return true;
}
bool ListDelete(SqList* L,int i) {
if (i < 0 || i >= L->length) {
return false;
}
if (L->length == 0) {
return false;
}
for (int j = i;j < L->length-1;j++) {
L->data[j] = L->data[j + 1];
}
L->length--;
return true;
}
int LocateElem(SqList* L ,int e) {
for (int i = 0;i < L->length;i++) {
if (L->data[i] == e) {
return i;
}
}
}
int main()
{
SqList L;
init(&L);
printf("插入前:");
MyPrint(L);
printf("\n");
ListInsert(&L, 4, 5);
printf("插入后:");
MyPrint(L);
printf("\n");
printf("删除后:");
ListDelete(&L, 6);
MyPrint(L);
printf("\n");
printf("第一个值为5的元素下标为:%d",LocateElem(&L,5));
return 0;
}