类的声明:
#pragma once
#include <iostream>
using namespace std;
template <class T>
class AvlTree {
template <class T>
class Node {
public:
T data;
int height;
Node<T>* lChild;
Node<T>* rChild;
Node(T d = 0, int h = 0, Node* lC = nullptr, Node* rC = nullptr) {
data = d;
height = h;
lChild = lC;
rChild = rC;
}
};
public:
AvlTree() {}
AvlTree(initializer_list<T>);
~AvlTree();
void insert(T data);
T findMin() const;
T findMax() const;
void print() const;
//先序遍历(递归)
void preTraverse() const;
//中序遍历(递归)
void inTraverse() const;
//后序遍历(递归)
void postTraverse() const;
void remove(T data);
private:
//查看节点
void visit(Node<T>* node) const;
Node<T>* insert(T data, Node<T>* t);
Node<T>* balance(Node<T>* t);
int height(Node<T>* t) const;
Node<T>* rotateWithLeftChild(Node<T>* desNode);
Node<T>* rotateWithRightChild(Node<T>* desNode);
Node<T>* doubleWithLeftChild(Node<T>* unbalanceNode);
Node<T>* doubleWithRightChild(Node<T>* unbalanceNode);
Node<T>* findMax(Node<T>* t) const;
Node<T>* findMin(Node<T>* t) const;
void print(Node<T>* t, int h) const;
//先序遍历(递归)
void preTraverse(Node<T>* node) const;
//中序遍历(递归)
void inTraverse(Node<T>* node) const;
//后序遍历(递归)
void postTraverse(Node<T>* node) const;
Node<T>* remove(T data, Node<T>* t);
void dostroy(Node<T>* t);
Node<T>*