题:用向量作存储结构,试设计一个算法,仅用一个辅助结点,实现将线性
表逆置的运算。
#include <iostream.h>
#define M 100
void main(){
int a[M]={1,2,3,4,5,6,7,8,9,10};//setting a list a;
int Length=10;
//Show the numbers of the list;
cout<<"Numbers of list a:";
for(int i=0;i<Length;i++)
cout<<a[i]<<" ";
cout<<endl;
//Inverting the list by exchanging the symmetrical elements;
for(i=0;i<(Length/2);i++){//Continuing untill it arrives the middle position.
int t=a[i];a[i]=a[Length-1-i];a[Length-1-i]=t;//Exchanging the symmetrical elements
}
//Show the numbers of the already-Inverted list;
for(i=0;i<Length;i++)
cout<<a[i]<<" ";
cout<<endl;
}