#include<iostream>
#include<cassert>
using namespace std;
template<class T>
class Node
{
private:
Node<T> * next;
public:
T data; //数据域
Node(const T & data, Node<T> * next = 0):data(data),next(next){} //构造函数
void InsertAfter(Node<T> *p){ //在本结点之后出入一个同类结点P
p->next = next; //P结点指针域指向当前结点的后继结点
next = p; //当前结点的指针域指向P
}
Node<T> *DeleteAfter(){ //删除本结点的后继结点,并返回其地址
Node<T>* tempp = next; //将欲删除的结点地址储存到tempp中
if (next == 0) //如果当前结点没有后继结点,则反回空指针
return 0;
next = tempp->next; //使当前结点的指针域指向tempp的后继结点
return tempp; //返回被删除的结点的地址
}
Node<T> *NextNode(){ return next; } //获取后继结点的地址
const Node<T>* NextNode()const{ return next; } //获取后继结点的地址
~Node(){}
};
template <class T>
class LinkedList {
private:
// 数据成员:
Node<T> *front, *rear; // 表头和表尾指针
Node<T> *prevPtr, *currPtr; // 记录表当前遍历位置的指针,由插入和删除操作更新
int size; // 表中的元素个数
int position; // 当前元素在表中的位置序号。由函数 Reset 使用
// 函数成员:
/
c++ 用类模版实现链表(c++语言程序设计第四版示例代码)
最新推荐文章于 2021-12-30 14:43:51 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)