//插入元素
Status ListInsert_Sq(SqList &L, int i, ElemType e)
{
ElemType *newbase,*p,*q;
if(i<1 || i>L.length+1) return ERROR; //i不合法
if (L.length >=L.listsize)
{ //当前空间已满,增加分配
newbase = (ElemType *)realloc(L.elem,(L.listsize+LISTINCREMENT)*sizeof(ElemType));
if (!newbase) exit(OVERFLOW); //分配失败
L.elem = newbase; //新基址
L.listsize +=LISTINCREMENT; // 增加容量
}
q = &(L.elem[i-1]); //q为插入位置
for (p=&(L.elem[L.length -1]);p>=q; --p)
*(p+1) = *p; //元素后移
*q = e; //插入
++L.length; //表长增长1
return OK;
} // ListInsert_Sq
我的问题是:
1插入元素的函数中~
1)L.elem[i-1]什么意思?
2)L.elem[L.length -1]什么意思?
3)为什么是--p?而不是p++?