int i;
for(i = 0; i < L->size; i++){
printf("%d ", L ->list[i]);
}
printf(" ");
return;
}
/* 7.从线性表 L 中查找值与 x 相等的元素,若查找成功则返回其位置,否则返回-1 */
int findList(struct List *L, elemType x)
{
int i;
for(i = 0; i < L->size; i++){
if(L->list[i] == x){
return i;
}
}
return -1;
}
/* 8.把线性表 L 中第 pos 个元素的值修改为 x 的值,若修改成功返回 1,否则返回 0 */
int updatePosList(struct List *L, int pos, elemType x)
{
if(pos < 1 || pos > L->size){ /* 若 pos 越界则修改失败 */
return 0;
}
L->list[pos - 1] = x;
return 1;
}
/* 9.向线性表 L 的表头插入元素 x */
void inserFirstList(struct List *L, elemType x)
{
int i;
if(L->size == L->maxSize){
againMalloc(L);
}
for(i = L->size - 1; i >= 0; i--){
L->list[i + 1] = L ->list[i];
}
L->list[0] = x;
L->size ++;
return;
}