插入:
#include<stdio.h>
#define N 100
typedef struct s
{int elem[N];int last;
}Seqlist;
int Locate(Seqlist l,int e)//查找
{int i=0;while(i<=l.last&&l.elem[i]!=e)i++;if(i<=l.last)return i+1;elsereturn 0;
}
int DelList(Seqlist *l,int *e,int i)//插入
{int k;if((i<1)&&(i>l->last+1)){return 0;}*e=l->elem[i-1];for(k=i;i<=l->last;k++)l->elem[k-1]=l->elem[k];l->last--;return 1; }int main()
{Seqlist l;//l.last=0;int m,i,n,k;scanf("%d",&n);for(i=0;i<n;i++){scanf("%d",&l.elem[i]);l.last++;}scanf("%d",&m);k=Locate(l,m);//查找位置 DelList(&l,&m,k);for(i=0;i<n-1;i++){printf("%d ",l.elem[i]);}printf("\n");return 0;
}
删除:
#include<stdio.h>
#define N 100
typedef struct s
{int elem[N];int last;
}Seqlist;
int Locate(Seqlist l,int e)//查找
{int i=0;while(i<=l.last&&l.elem[i]!=e)i++;if(i<=l.last)return i+1;elsereturn 0;
}
int DelList(Seqlist *l,int *e,int i)//插入
{int k;if((i<1)&&(i>l->last+1)){return 0;}*e=l->elem[i-1];for(k=i;i<=l->last;k++)l->elem[k-1]=l->elem[k];l->last--;return 1; }int main()
{Seqlist l;//l.last=0;int m,i,n,k;scanf("%d",&n);for(i=0;i<n;i++){scanf("%d",&l.elem[i]);l.last++;}scanf("%d",&m);k=Locate(l,m);//查找位置 DelList(&l,&m,k);for(i=0;i<n-1;i++){printf("%d ",l.elem[i]);}printf("\n");return 0;
}