list双向链表迭代器的实现

cpp 复制代码
// typedef __list_iterator<T, T&, T*> iterator;
	// typedef __list_iterator<T, const T&, const T*> const_iterator;
	template<class T, class Ref, class Ptr>
	struct __list_iterator
	{
		typedef list_node<T> Node;
		typedef __list_iterator<T, Ref, Ptr> self;
		Node* _node;

		__list_iterator(Node* node)
			:_node(node)
		{}

		Ref operator*()
		{
			return _node->_val;
		}

		Ptr operator->()
		{
			return &_node->_val;
		}

		self& operator++()
		{
			_node = _node->_next;
			return *this;
		}

		self operator++(int)
		{
			self tmp(*this);

			_node = _node->_next;

			return tmp;
		}

		self& operator--()
		{
			_node = _node->_prev;
			return *this;
		}

		self operator--(int)
		{
			self tmp(*this);

			_node = _node->_prev;

			return tmp;
		}

		bool operator!=(const self& it) const
		{
			return _node != it._node;
		}

		bool operator==(const self& it) const
		{
			return _node == it._node;
		}
	};
相关推荐
LiLiYuan.1 天前
Arrays类和List接口的关联
java·开发语言·windows·python
flashlight_hi1 天前
LeetCode 分类刷题:1669. 合并两个链表
javascript·leetcode·链表
SJjiemo1 天前
轻松设置-系统优化万能工具
windows
Zero不爱吃饭1 天前
环形链表(C)
数据结构·链表
灵晔君1 天前
C++标准模板库(STL)——list的使用
c++·list
百事牛科技1 天前
PPT如何添加logo?两种方法解决!
windows·powerpoint
朱一头zcy2 天前
Win11右键菜单如何把“显示更多选项“中的内容改为默认展示出来
windows
FOREVER-Q2 天前
Windows 下 Docker Desktop 快速入门与镜像管理
运维·服务器·windows·docker·容器
2401_861277552 天前
软考程序员2016年上半年二叉排序树案例题解答
c语言·决策树·链表
任子菲阳2 天前
学Java第四十五天——斗地主小游戏创作
java·开发语言·windows