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;
		}
	};
相关推荐
因兹菜6 小时前
[LeetCode]day9 203.移除链表元素
算法·leetcode·链表
青草地溪水旁11 小时前
c++ list的front和pop_front的概念和使用案例
c++·容器·list
_周游11 小时前
【数据结构】_链表经典算法OJ(力扣/牛客第二弹)
数据结构·算法·链表
大道戏12 小时前
如何本地部署DeepSeek
windows·ai·deepseek
青草地溪水旁13 小时前
c++ list的front和pop_front的概念和使用案例—第2版
开发语言·c++·list
skywalk816314 小时前
在Windows下安装Ollama并体验DeepSeek r1大模型
人工智能·windows·ollama·deepseek
康世行19 小时前
Windows环境下MaxKB大模型 Docker部署图文指南
windows·docker·容器
遗落凡尘的萤火-生信小白1 天前
单细胞-第四节 多样本数据分析,下游画图
windows·数据挖掘·数据分析
2401_858286111 天前
L30.【LeetCode笔记】设计链表
开发语言·c++·笔记·算法·leetcode·链表
西农小陈1 天前
Python-基于PyQt5,json和playsound的通用闹钟
开发语言·windows·python·pycharm·pyqt