线性表的插入操作
int insert(Vec *v,int idx,int val) {
if (!v) return 0;
if (idx<0||idx>v->len )return 0;
if (v->len == v->size)return 0;
memcpy(v->data +idx+1,v->data +idx,sizeof(int)*(v->len -idx));
v->data[idx] = val;
v->len++;
return 1;
}
线性表的删除
int erase(Vec*v,int idx) {
if (!v)return 0;
if (idx < 0 || idx >= v->len)return 0;
memcpy(v->data +idx,v->data+idx+1,sizeof(int)*(v->len-idx-1));
v->len--;
return -1;
}