diff --git a/TinySTL/AVLTree.h b/TinySTL/AVLTree.h new file mode 100644 index 0000000..3912e6e --- /dev/null +++ b/TinySTL/AVLTree.h @@ -0,0 +1,40 @@ +#ifndef _AVL_TREE_H_ +#define _AVL_TREE_H_ + +#include "Allocator.h" + +namespace TinySTL{ + //class of avl tree + template + class avl_tree{ + public: + typename T value_type; + private: + struct node{ + T data_; + node *left_, *right_; + size_t height_; + explicit node(T d = T(), node *l = 0, node *r = 0, size_t h = 0) + :data_(d), left_(l), right_(r), height_(h){} + }; + typedef TinySTL::allocator dataAllocator; + private: + node *root_; + public: + avl_tree() :root_(0){} + avl_tree(const avl_tree&) = delete; + avl_tree& operator = (const avl_tree&) = delete; + ~avl_tree(){ destroyAndDeallocateAllNodes(root_); } + private: + void destroyAndDeallocateAllNodes(node *p){ + if (p != 0){ + destroyAndDeallocateAllNodes(p->left_); + destroyAndDeallocateAllNodes(p->right_); + dataAllocator::destroy(p); + dataAllocator::deallocate(p); + } + } + }; +} + +#endif \ No newline at end of file diff --git a/TinySTL/TinySTL.vcxproj b/TinySTL/TinySTL.vcxproj index d42101c..fd62738 100644 --- a/TinySTL/TinySTL.vcxproj +++ b/TinySTL/TinySTL.vcxproj @@ -86,6 +86,7 @@ + diff --git a/TinySTL/TinySTL.vcxproj.filters b/TinySTL/TinySTL.vcxproj.filters index ce861fc..57f3834 100644 --- a/TinySTL/TinySTL.vcxproj.filters +++ b/TinySTL/TinySTL.vcxproj.filters @@ -83,5 +83,8 @@ 头文件 + + 头文件 + \ No newline at end of file