#include<iostream>
using namespace std;
//定义链表节点
template<class T>
struct CBListNode {
CBListNode(const T& x=T())//链表节点构造函数
:data(x)
, next(nullptr)
, prev(nullptr)
{}
T data;//数据域
CBListNode<T>* next;
CBListNode<T>* prev;
};
//封装迭代器
template<class T>
class CBListIterator {
public:
typedef CBListNode<T> Node;
typedef CBListIterator<T> Self;
public:
CBListIterator( Node* node)
:_node(node)
{}
T& operator*() {
return _node->data;
}
T* operator->() {
return &(operator*());
}
bool operator==(const Self& s) {
return _node == s._node;
}
bool operator!=(const Self& s) {
return _node != s._node;
}
Self& operator++() {
_node = _node->next;
return *this;
}
Self& operator++(int) {
Self temp = *this;
_node = _node->next;
return temp;
}
Self& operator--() {
_node = _node->prev;
return this
带头节点的双向循环链表的模拟实现以及链表内部算法的实现(排序、逆置)和内部迭代器的封装
最新推荐文章于 2023-09-18 09:22:44 发布
本文详细介绍了如何模拟实现带头节点的双向循环链表,并探讨了链表内部的排序和逆置算法。同时,文章还讨论了如何封装链表的内部迭代器,以方便进行高效的数据操作。
摘要由CSDN通过智能技术生成