list.h
#pragma once
#include<iostream>
using namespace std;
template <typename Datatype>
struct tree
{
Datatype data;
tree* next;
};//链表结构
template <typename Datatype>
class Tree
{
public:
void create(tree<Datatype>* &L)
{
L = new tree<Datatype>;
L->next = NULL;
}
void push(tree<Datatype>* L,int i,Datatype know)
{
int calucator = 0;
while (calucator < i && L->next)
{
L = L->next;
calucator++;
}
auto q = new tree<Datatype>;
q->next = L->next;
L->next = q;
q->data = know;
}
void Delete(tree<Datatype>* L, int i)
{
int k = 0;
while (L && k < i - 1)
{
L = L->next;
k++;
}
auto q = L->next;
L->next = q->next;
delete q;
q = NULL;
}
int heighten(tree<Datatype>* L)
{
int j = 0;
L = L->next;
while (L)
{
L = L->next;
j++;
}
return j;
}
void Destory(tree<Datatype>* L)
{
while (L)
{
Delete(L->next);
delete L;
L = NULL;
}
}
void output(tree<Datatype>* L)
{
L = L->next;
while (L)
{
cout << L->data<<endl;
L = L->next;
}
}
private:
};
List.cpp
#include<iostream>
#include"list.h"
using namespace std;
int main()
{
Tree<int> TReenode;
tree<int>* L = NULL;
TReenode.create(L);
TReenode.push(L, 1, 3);
TReenode.push(L, 2, 54);
TReenode.push(L, 3, 35);
TReenode.push(L, 4, 35443);
TReenode.output(L);
}