顺序表的转置
#include<iostream>
using namespace std;
typedef int ElemType;
const int MaxSize = 1000;
class SequenList
{
protected:
ElemType a[MaxSize];
int len;
public:
void exchange( int n) //逆置
{
for(int i = 0;i<=n/2-1;i++)
{
ElemType t = a[i];
a[i] = a[n-i-1];
a[n-i-1]=t;
}
}
void input(int n)
{
len = n;
for(int i = 0;i<n;i++)
{
cin>>a[i];
}
}
void print(int n)
{
for(int i = 0;i<=n-1;i++)
{
cout<<a[i]<<' ';
}
cout<<endl;
}
};
int main()
{
int n;
cout<<"请输入表中元素个数"<<endl;
cin>>n;
SequenList a;
cout<<"请输入表中元素值"<<endl;
a.input(n);
a.print(n);
a.exchange(n);
a.print (n);
system("pause");
return 0;
}
作者“程序人生”
补充:软件开发 , C语言 ,