赞
踩
顺序表 | 数组下标 |
---|---|
a1 | 0 |
a2 | 1 |
a3 | 2 |
… | … |
an | n-1 |
由上表可以直观看到,顺序表中的序号是从1开始的,而数组下标是从0开始的,所以,在代码的编写过程中,要格外注意这个区别。
下列顺序表中的插入元素e操作为例:
bool ListInsert(SqList &L,int i,ElemType e)
{
if(i<1IIi>L.length+1)
return false;
if(L.length>MaxSize)
return false;
for(int j=L.length;j>=i;j–)
L.data[j]=l.data[j-1];
L.data[j-1]=e;
L.length++;
return true;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。