C语言顺序表创建及其操作,很纯的C
1.静态结构操作
L = (struct SqList*)malloc(sizeof(struct SqList)*3);L这一个指针指向的是一个数组,数组有三个元素,数组每一个元素都是结构体,这个不是结构体指针数组。
#include <stdio.h>
#include <stdlib.h>
#include<stdbool.h>
#define maxsize 20
struct SqList
{
int length;
int data[maxsize];
};
void InitList(struct SqList *L) {
L->length = 0;
for (int i = 0; i < 20;i++) {
L->data[i] = 0;
}
}
bool ListInsert(struct SqList* L, int i, int e) {
//i为索引,e为插入值
if (i<0 || i>L->length) {
return false;
}
for (int j = L->length; j >i; --j) {
//printf("j:%d", j);
L->data[j] = L->data[j - 1];
}
L->data[i] = e;
L->length += 1;
return true;
}
bool ListDelete(struct SqList* L, int i) {
if (i<0 || i>=L->length) {
return false;
}
for (int j &#