#include <iostream>
using namespace std;
const int MaxSize = 100;
template<class T>
class SeqList
{
public:
SeqList() { length = 0; }
SeqList(T a[], int n);
~SeqList();
void ReverseM();
void PrintList();
template<class T> friend void Re(SeqList<T>& d);
private:
T *data;
int length;
};
template<class T>
SeqList<T>::SeqList(T a[], int n)
{
data = new T[n];
for (int i = 0; i < n; i++)
data[i] = a[i];
length = n;
}
template<class T>
SeqList<T>::~SeqList()
{
delete[] data;
}
template<class T>
void SeqList<T>::ReverseM()
{
for (int i = 0; i < length / 2; i++)
{
T temp;
temp = data[i];
data[i] = data[length - 1 - i];
data[length - 1 - i] = temp;
}
}
template<class T>
void SeqList<T>::PrintList()
{
for (int i = 0; i < length; i++)
cout << data[i] << "";
cout << endl;
}
template<class T>
void Re( SeqList<T> &a)
{
for (int i = 0; i < a.length / 2; i++)
{
T temp;
temp = a.data[i];
a.data[i] = a.data[a.length - 1 - i];
a.data[a.length - 1 - i] = temp;
}
}
int main()
{
int a[5] = { 1,2,3,4,5 };
SeqList<int> d(a, 5);
d.ReverseM();
Re(d);
d.PrintList();
}
|