![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/504714050236112.jpg?x-oss-process=image/auto-orient,1/resize,w_320,m_lfit)
```c
//预处理
#include <stdio.h>
#include<malloc.h>
#include<stdlib.h>
#define TURE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBALE -1//不可执行的
#define OVERFLOW -2
#define list_init_size 100
#define LISTINCREMENT 10
typedef int status;
typedef int elemtype;
typedef struct
{
elemtype* elem;//存储空间基址
int length;//线性表的长度
int listsize;//线性表当前的空间
}SqList;
//新建空表
status initlist_Sq(SqList& L) {
L.elem = (elemtype*)malloc(list_init_size * sizeof(elemtype));
if (!L.elem)exit(OVERFLOW);
L.length = 0;
L.listsize = list_init_size;
return OK;
}
void display(SqList L)//展示
{
int i;
for(i=0;i<=L.length-1;i++) //定义for循环函数
printf("%d\n",L.elem[i]);
}
//给顺序表赋上100以内奇数
status listinsert_Sq(SqList &L,int k,elemtype *q)
{
int i=1,j=0;
while(i)
{
q=(int *)malloc(sizeof(int));
if(q[j]==k-1)
{
free(q);
break;
}
else
{
L.elem[L.length]=*(q+j);
L.length+=1;
}
j++;
}
return OK;
}
//删除
status listdelete_Sq(SqList *L,int i,elemtype &x)
{
int k;
if(L->length==0)
{
printf("线性表为空\n");
return ERROR;
}
else if(i<1||i>L->length)
{
printf("要删除的元素不存在\n");
return ERROR;
}
else
{
printf("要删除的元素存在\n");
x=L->elem[i-1];
for(k=1;k<L->length;k++)
L->elem[k-1]=L->elem[k];
L->length--;
return(x);
}
}
void main()
{
int a[50];
int *p=a;
for(int k=0;k<50;k++) //赋值给数组
{
a[k]=2*k+1; //注意公式,从0开始算
}
SqList L; //定义线性表
initlist_Sq(L); //调用空表
elemtype e;
listinsert_Sq(L,100,p);
listdelete_Sq(&L,2,e);
display(L);
printf("%d\n",e);
}