HolyAVLTree
This commit is contained in:
38
BinaryTree/BalanceTree/AVLTree/treenode.h
Normal file
38
BinaryTree/BalanceTree/AVLTree/treenode.h
Normal file
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// Created by PC on 25-8-17.
|
||||
//
|
||||
|
||||
#ifndef TREENODE_H
|
||||
#define TREENODE_H
|
||||
template<class T>
|
||||
class TreeNode {
|
||||
public:
|
||||
T element;
|
||||
TreeNode<T>* left;
|
||||
TreeNode<T>* right;
|
||||
int height;
|
||||
|
||||
TreeNode(): left(nullptr), right(nullptr), height(0) {}
|
||||
explicit TreeNode(T e): element(e), left(nullptr), right(nullptr), height(1) {}
|
||||
TreeNode(T e, TreeNode<T>* l, TreeNode<T>* r): element(e), left(l), right(r), height(1) {}
|
||||
};
|
||||
|
||||
#endif //TREENODE_H
|
||||
/*
|
||||
30
|
||||
/ \
|
||||
25 35
|
||||
/ \
|
||||
20 32
|
||||
/
|
||||
5
|
||||
|
||||
旋转之后应该是:
|
||||
1
|
||||
/ \
|
||||
r 4
|
||||
/ \
|
||||
3 2
|
||||
/
|
||||
5
|
||||
*/
|
Reference in New Issue
Block a user