要求:
试写一算法,实现顺序表的就地逆置,即利用原表的储存空间将线性表(a1,…,an)逆置为(an,…,a1)
C语言实现
//顺序表的逆置
Status ListOppose_Sq(SqList &L)
{
int i;
ElemType x;
for(i=0;i<L.length/2;i++){
x=L.elem[i];
L.elem[i]=L.elem[L.length-1-i];
L.elem[L.length-1-i]=x;
}
return OK;
}
要求:
试写一算法,实现顺序表的就地逆置,即利用原表的储存空间将线性表(a1,…,an)逆置为(an,…,a1)
C语言实现
//顺序表的逆置
Status ListOppose_Sq(SqList &L)
{
int i;
ElemType x;
for(i=0;i<L.length/2;i++){
x=L.elem[i];
L.elem[i]=L.elem[L.length-1-i];
L.elem[L.length-1-i]=x;
}
return OK;
}