### 1.建表

#define max 20typedef struct {int data[max];int length;}SqList;

### 2.获得元素

int Get(SqList*L,int i,int e){if(L->length==0){printf("这是一个空表");return;}if(i<1||i>L->length){printf("传入参数数值错误");return;}e=L->data[i-1];return e;}

### 3.插入元素

void Insert(SqList*L,int i,int e){if(L->length==max){printf("表满了");return;}if(i<1||i>L->length+1){printf("非法操作");return;}for(int j=L->length-1;j>=i-1;j--)L->data[j+1]=L->data[j];L->length++;L->data[i-1]=e;}

### 4.删除元素

void Delete(SqList*L,int i){if(L->length==0){printf("这是一个空表");return;}if(i<1||i>L->length){printf("非法操作");return;}for(int k=i-1;k<L->length;k++)L->data[k]=L->data[k+1];L->length--;}

### 5.代码部分

#include<stdio.h>#include<malloc.h>#define max 20//建表typedef struct{  int data[max];  int length;}SqList;//获得元素int Get(SqList* L, int i, int e){  if (L->length == 0)  {    printf("这是一个空表");    return;  }  if (i<1 || i>L->length)  {    printf("传入参数数值错误");    return;  }  e = L->data[i - 1];  return e;}//插入元素void Insert(SqList* L, int i, int e){  if (L->length == max)  {    printf("表满了");    return;  }  if (i<1 || i>L->length + 1)  {    printf("非法操作");    return;  }  for (int j = L->length - 1; j >= i - 1; j--)    L->data[j + 1] = L->data[j];  L->length++;  L->data[i - 1] = e;}//删除元素void Delete(SqList* L, int i){  if (L->length == 0)  {    printf("这是一个空表");    return;  }  if (i<1 || i>L->length)  {    printf("非法操作");    return;  }  for (int k = i - 1; k < L->length; k++)    L->data[k] = L->data[k + 1];  L->length--;}int main(){  SqList* L = (SqList*)malloc(sizeof(SqList));  L->length = 0;//开始为0  for (int i = 0; i < 10; i++)  {    L->data[i] = i;    L->length++;  }  int li = 0;  //获得元素  for (int i = 1; i <= L->length; i++)//打印初始表  {    li = Get(L, i, li);    printf("%d ", li);  }  printf("\n");  //插入元素  for (int i = 1; i <= 5; i += 2)//注意i从1开始    Insert(L, i, 2*i);  for (int i = 1; i <= L->length; i++)//打印插入元素后的表  {    li = Get(L, i, li);    printf("%d ", li);  }  printf("\n");  //删除元素  for (int i = 2; i <= 5; i += 2)    Delete(L, i);  for (int i = 1; i <= L->length; i++)//打印删除元素后的表  {    li = Get(L, i, li);    printf("%d ", li);  }  printf("\n");  free(L);  return 0;}