已知顺序表类模板的C描述如下

已知顺序表类模板的C++描述如下:

templateclassT

classLinearList

{

public:

LinearList(intLLMaxSize);//构造函数,创建空表

~LinearList();//析构函数,删除表

LinearListTInsert(intk,constTx);

//在第k个位置插入元素x,返回插入后的线性表

boolIsEmpty()const;

//判断表是否为空,表空返回true,表非空返回false

intGetLength()const;//返回表中数据元素的个数

boolGetData(intk,Tx);

//将表中第k个元素保存到x中,不存在则返回false

boolModifyData(intk,constTx);

//将表中第k个元素修改为x,不存在则返回false

intFind(constTx);//返回x在表中的位置,如果x不在表中返回0

LinearListTDeleteByIndex(constintk,Tx);

//删除表中第k个元素,并把它保存到x中,返回删除后的线性表

LinearListTDeleteByKey(constTx,Ty);

//删除表中关键字为x元素,返回删除后的线性表

voidOutPut(ostreamout)const;

//将线性表放到输出流out中输出

private:

intlength;//当前数组元素个数

intMaxSize;//线性表中最大元素个数

T*element;//一维动态数组

};

intmain()

{

LinearListintIntegerLList(10);

inti,x;

for(i=1;i11;i++)

IntegerLList.Insert(i,i*5);

for(i=3;i5;i++)

{

IntegerLList.DeleteByIndex(i,x);

coutxendl;

}

coutendl;

return0;

}

请写出主函数main执行后在屏幕上的输出结果。

[答案]:

15

25




转载请注明:http://www.aierlanlan.com/tzrz/7347.html

  • 上一篇文章:
  •   
  • 下一篇文章: 没有了