[求助]这是什么用法?
处理一个数组构成的线性表,动态产生线性表,并输出线性表中的数据有个地方不明白
#include<iostream.h>
class ListClass
{
int *List;
unsigned nMax;
unsigned nElem;
public:
void Init(int n=10)
{
List=new int[n];
nMax=n;
nElem=0;
}
int Elem(int);
int &Elem(unsigned n){return List[n];}
unsigned Elem(void){return nElem;}
unsigned Max(void){return nMax;}
void print(void);
int GetElem(int i)
{
if((i>=0)&&(i<=nElem)) return List[i];
else return 0;
}
void Destroy(void) {delete [nMax]List;}
};
int ListClass::Elem(int elem)
{
if (nElem<nMax){
List[nElem++]=elem;
return nElem;
}
else {
int *list;
list=new int[nMax+1];
for(int i=0;i<nElem;i++)list[i]=List[i];
delete [nMax]List;
nMax++;
List=list;
List[nElem++]=elem;
return nElem;
}
}
void ListClass::print(void)
{
for(int i=0;i<nElem;i++)cout<<List[i]<<'\t';
cout<<'\n';
}
void main(void)
{
ListClass list,list1;
list.Init(10);
list1.Init(20);
for(int i=0;i<10;i++)
list1.Elem(i);
cout<<"线性表list的元素的个数为:"<<list.Elem()<<'\n';
cout<<"线性表list的长度为:"<<list.Max()<<'\n';
cout<<"线性表list1的元素的个数为:"<<list1.Elem()<<'\n';
cout<<"线性表list1的长度为:"<<list1.Max()<<'\n';
list1.print();
list1.Elem(3u)=100;//这是什么用法?
cout<<"现在线性表list1中的第三个值为:"<<list1.Elem(3u)<<'\n';
list1.Elem(20);
list1.Elem(200);
cout<<"现在线性表list1中元素的个数为:"<<list1.Elem()<<'\n';
list1.print();
cout<<"线性表list中的最后一个元素为:"<<list1.GetElem(list1.Elem()-1)<<'\n';
list.Destroy();
list1.Destroy();
}