#include<stdio.h>
#include<stdlib.h>
#define M 10
typedef struct //数据类型
{
int elem[M];
int length;
}seqlist; //类型名称
void createsqlist(seqlist *L,int n) //输入
{
int i=0;
for(i=0;i<n;i++)
scanf("%d",&L->elem[i]);
L->length=n;
}
void print(seqlist L,int n) //输出
{
int i;
for(i=0;i<n;i++)
printf("%d ",L.elem[i]);
}
void chushihua(seqlist &L) //初始化
{
struct seqlist *p;
p=(seqlist*)malloc(sizeof(L));
L.length=0;
}
int locateelem(seqlist L,int e) //查找
{
int j;
for(j=0;j<L.length;j++)
if(L.elem[j]==e)
{
return j+1;
}
return 0;
}
int listinsert(seqlist L,int i,int e) //插入
{
int j;
if((i<1)||(i>L.length+1))
return 0;
for(j=L.length-1;j>=i-1;j--)
L.elem[j+1]=L.elem[j];
L.elem[j-1]=e;
L.length=L.length+1;
return 1;
}
int listdelete(seqlist &L,int i,int e) //删除
{
int j;
if((i<1)||(i>L.length))
return 0;
e=L.elem[i];
for(j=i;j<=L.length-1;j++)
L.elem[j-1]=L.elem[j];
L.length=L.length-1;
return 1;
}
int main()
{
int m,a,b,c;
seqlist L;
scanf("%d%d%d%d",&m,&a,&b,&c);
chushihua(L);
switch(a)
{
case 1:locateelem(L,b);break; //查找
case 2:listinsert(L,b,c);break; //插入
case 3: listdelete(L,b,c);break; //删除
case 4:createsqlist(&L,m);break;
case 5:print(L,m);
}
print(L,m);
return 0;
}
插入 删除 查找