list 是一个双向循环链表
结点类:
template<class T>
struct list_node // 节点
{
T _data;
list_node<T>* _next;
list_node<T>* _prev;
list_node(const T& x = T())
: _data(x)
, _next(nullptr)
, _prev(nullptr)
{}
};
迭代器类:
template<class T, class Ref, class Ptr>
struct __list_iterator
{
typedef list_node<T> Node;
typedef __list_iterator<T, Ref, Ptr> iterator;
Node* _node;
//.....
};
list 类:
template<class T>
class list
{
typedef list_node<T> Node;
public:
typedef __list_iterator<T, T&, T*> iterator;
typedef __list_iterator<T, const T&, const T*> const_iterator;
//......
private:
Node* _head;
};
list类中包含上面两个类。
下面介绍list常用接口的使用。
void list_test1()
{
list<int> l1; // 构造空的l1
list<int> l2(4, 100);
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- huatuo9.cn 版权所有 赣ICP备2023008801号-1
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务