编写自己的list容器
来源:互联网 发布:sop流程图软件 编辑:程序博客网 时间:2024/06/06 00:55
//编写自己的容器#include <iostream>#include <string>template<typename T>class List{public: List() { _pHead = NULL; _pTail = NULL; } struct Node { T data; Node* pNext; }; class iterator { public: iterator() { _pCur = NULL; } iterator(Node* pNode) { _pCur = pNode; } bool operator != (const iterator& it) { return !(_pCur == it._pCur); } iterator operator ++(int) { iterator it(_pCur); _pCur = _pCur->pNext; return it; } T operator *()//取指针上的数据 { return _pCur->data; } protected: Node* _pCur; }; void push_back(const T&val) { Node* pNew = new Node; pNew->data = val; pNew->pNext = NULL; if(_pHead == NULL&& _pTail == NULL) { _pHead = pNew; _pTail = pNew; } else { _pTail->pNext = pNew; _pTail = pNew; } } iterator begin() { return iterator(_pHead); } iterator end() { return iterator(_pTail->pNext); }protected: Node* _pHead;//头 Node* _pTail;//尾部};//#include<list>using namespace std;void main(){ List<int> lst; lst.push_back(10); lst.push_back(20); lst.push_back(30);// lst.push_back(40); List<int>::iterator it; for(it = lst.begin();it != lst.end();it++) { cout<<*it<<endl; }}
0 0
- 编写自己的list容器
- 自己编写的List
- 编写一个循环将list容器的元素逆序输出
- 自己实现C++list容器
- 动手实现自己的 STL 容器《2》---- list
- 编写程序将一个list容器的所有元素赋值给一个vector容器。
- list容器的函数
- list 容器的用法
- list 容器的用法
- list容器的实现
- list容器的使用
- List容器的详解
- list容器的使用方法
- //编写程序判断一个vector<int>容器所包含的元素是否与一个list<int>容器的完全相同
- JAVA企业应用的反思--编写自己的容器--名字叫《蜗居》
- 编写自己的IDE
- 编写自己的IDE
- 编写自己的IDE
- JAR 文件揭密
- Myeclipse6.5 + Maven 开发web工程详细配置(二)
- 使用Tcmalloc进行堆栈分析
- 润乾集算报表多样性数据源之混合多源
- redis学习笔记2,配置文件
- 编写自己的list容器
- MATLAB批量读取文件代码
- ubuntu循环登录或登录后黑屏
- Lua 学习笔记(六) —— 迭代器和泛型for
- EasyUI Combobox 设置默认值
- handler用法
- iOS XMPP App run background (by voip)
- Find Minimum in Rotated Sorted Array
- 友推sdk集成常见问题2:为什么demo中微信和新浪微博无法分享,微信甚至不能调出微信界面?