- UID
- 580
- 精华
- 积分
- 561
- 威望
- 点
- 宅币
- 个
- 贡献
- 次
- 宅之契约
- 份
- 最后登录
- 1970-1-1
- 在线时间
- 小时
|
C++模板实现的单向链表,实现了链表的初始化创建,元素插入,元素链表末尾添加,元素删除,链表清空
Lists.hmain.cpp- //main.cpp
- #include <iostream>
- #include "Lists.h"
- using namespace std;
- void main()
- {
- cout<<"*************************Test list init***************************"<<endl;
- Lists<int> Lisa;
- cout<<"List's length is:"<<Lisa.getLength()<<endl;
- cout<<"List is empty:"<<Lisa.isEmpty()<<endl;
- cout<<"*************************Test list add element********************"<<endl;
- Lisa.add(1);
- Lisa.add(2);
- Lisa.add(3);
- Lisa.add(4);
- Lisa.add(5);
- Lisa.print();
- cout<<"List's length is:"<<Lisa.getLength()<<endl;
- cout<<"List is empty:"<<Lisa.isEmpty()<<endl;
- cout<<"*************************Test list insert*************************"<<endl;
- Lisa.insert(-1,0);
- Lisa.insert(11,2);
- Lisa.insert(100,6);
- Lisa.print();
- cout<<"List's length is:"<<Lisa.getLength()<<endl;
- cout<<"List is empty:"<<Lisa.isEmpty()<<endl;
- cout<<"*************************Test list erase**************************"<<endl;
- Lisa.erase(0);
- Lisa.erase(2);
- Lisa.erase(5);
- Lisa.print();
- cout<<"List's length is:"<<Lisa.getLength()<<endl;
- cout<<"List is empty:"<<Lisa.isEmpty()<<endl;
- cout<<"*************************Test list clear**************************"<<endl;
- Lisa.clear();
- Lisa.print();
- cout<<"List's length is:"<<Lisa.getLength()<<endl;
- cout<<"List is empty:"<<Lisa.isEmpty()<<endl;
- }
复制代码 程序运行结果:
|
|