#include<bits/stdc++.h>
using namespace std;
template<class T>
class List; //提前声明配合友元类
template<class T>
class Node{
friend class List<T>;//友元类,方便表头操作节点私有成员
T data; //数据域
Node<T>*next; //指针域,下一个元素的地址
public:
Node(T data){
this->data = data;
this->next = nullptr;
}
};
template<class T>
class List{
Node<T>*head;
int length;
public:
List(){
this->head = nullptr;
this->length = 0;
}
//isEmpty()判断链表是否为空
bool isEmpty(){
if(this->head==nullptr)
{
return true;
}
else{
return false;
}
}
//append()尾插法
void append(T data){
if(this->isEmpty())
{
this->head = new Node<T>(data
C++ ——自己手写的一个简单的单向链表
最新推荐文章于 2024-03-15 21:39:59 发布