# 线性表操作(线性表)

（线性表）请你定义一个线性表，可以对表进行“在某个位置之前插入一个元素”、“删除某个位置的元素”、“清除所有元素”、“获取某个位置的元素”等操作。键盘输入一些命令，可以执行上述操作。本题中，线性表元素为整数，线性表的第一个元素位置为1。线性表的最大长度为1000。

``````insert
2
1 1
2 2
delete
1
clear
insert
2
1 3
2 4
getelem
2
exit
``````

``````1
4
``````

``````#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int n,m,i,j;
char c[10],d[4][10]={"insert","clear","getelem","delete"};
gets(c);
while(strcmp(c,"exit"))
{
struct
{
int date;
}*s;
if(!strcmp(c,d[0]))
{
scanf("%d",&n);
s=malloc(sizeof(*s)*n);
for(i=0;i<n;i++)
{
scanf("%d",&j);
scanf("%d",&s[j].date);
}
getchar();
}
else if(!strcmp(c,d[1]))
{
s=NULL;
}
else if(!strcmp(c,d[2]))
{
scanf("%d",&m);
printf("%d\n",s[m].date);
getchar();
}
else if(!strcmp(c,d[3]))
{
scanf("%d",&m);
printf("%d\n",s[m].date);
getchar();
}
gets(c);
}
return 0;
}``````

``````#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int n,m,i,j;
char c[10],d[4][10]={"insert","clear","getelem","delete"};
gets(c);
while(strcmp(c,"exit"))
{
struct
{
int date;
}*s;
if(!strcmp(c,d[0]))
{
scanf("%d",&n);
s=malloc(sizeof(*s)*n);
for(i=0;i<n;i++)
{
scanf("%d",&j);
scanf("%d",&s[j].date);
}
getchar();
}
else if(!strcmp(c,d[1]))
{
s=NULL;
}
else if(!strcmp(c,d[2]))
{
scanf("%d",&m);
printf("%d\n",s[m].date);
getchar();
}
else if(!strcmp(c,d[3]))
{
scanf("%d",&m);
printf("%d\n",s[m].date);
getchar();
}
gets(c);
}
return 0;
}``````