版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/dyw_666666/article/details/82796302
向类型有Sqlist的顺序表L的第i个元素(0<=i<=L.len)之后插入一个新元素x。
Status ListInsert(SqList *L,int i,ElemType x)
{
// 向线性表L中第i个元素之后插入值为x的新元素
if( L->length == 0 ) // 顺序表为空
return ERROR;
if( i<0 || i>L->length ) // 当i不在范围内时
return ERROR;
for( j=L->length; j>=i+1; j-- )
{
L->data[j+1] = L->data[j];
}
L->data[i+1] = x;
L->length++;
return OK;
}