程序如下:
template<class T>
class LinearList {
public:
LinearList(int MaxListSize = 10); // constructor
~LinearList() {delete [] element;} // destructor
bool IsEmpty() const {return length == 0;}
int Length() const {return length;}
bool Find(int k, T& x) const;
// return the k'th element of list in x
int Search(const T& x) const;
// return position of x
LinearList<T>& Delete(int k, T& x);
// delete k'th element and return in x
LinearList<T>& Insert(int k, const T& x);
// insert x just after k'th element
LinearList<T>& Reverse();
LinearList<T>& Merge(LinearList& a,LinearList& b,LinearList* list);
void Output(ostream& out) const;
private:
int length;
int MaxSize;
T *element; // dynamic 1D array
};template<class T>
LinearList<T>::LinearList(int MaxListSize)
{// Constructor for formula-based linear list.
MaxSize = MaxListSize;
element = new T[MaxSize];
length = 0;
}
当在程序中调用Merge方法的时候,如何访问传入的a和b的element这个数组中的元素?
template<class T>
class LinearList {
public:
LinearList(int MaxListSize = 10); // constructor
~LinearList() {delete [] element;} // destructor
bool IsEmpty() const {return length == 0;}
int Length() const {return length;}
bool Find(int k, T& x) const;
// return the k'th element of list in x
int Search(const T& x) const;
// return position of x
LinearList<T>& Delete(int k, T& x);
// delete k'th element and return in x
LinearList<T>& Insert(int k, const T& x);
// insert x just after k'th element
LinearList<T>& Reverse();
LinearList<T>& Merge(LinearList& a,LinearList& b,LinearList* list);
void Output(ostream& out) const;
private:
int length;
int MaxSize;
T *element; // dynamic 1D array
};template<class T>
LinearList<T>::LinearList(int MaxListSize)
{// Constructor for formula-based linear list.
MaxSize = MaxListSize;
element = new T[MaxSize];
length = 0;
}
当在程序中调用Merge方法的时候,如何访问传入的a和b的element这个数组中的元素?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货