#ifndef LINKLIST_H
#define LINKLIST_H
#include <iostream>
using namespace std;
template <typename T>
struct Node{
T data;
struct Node* next;
};
template <typename T>
class LinkList:public Node<T>
{
public:
LinkList();
~LinkList();
void insert(const T& value, const int& pos); //指定位置插入
void append(const T& value);
bool removeBy_pos(const int& pos);
bool removeBy_value(const T& value);
int size() const;
Node<T>* front();
void print();
void clear();
int find(const T& value);
void reverseList(); //翻转链表
private:
Node<T> * head;
int _size;
};
template<typename T>
LinkList<T>::LinkList():_size(0)
{
head = new Node<T>;
head->next = NULL;
}
template<typename T>
void LinkList<T>::insert(const T& value, const int& pos)
{
if(pos < this->_size) {
auto *n
C++模板实现单链表基本操作
最新推荐文章于 2024-05-05 18:00:32 发布