提交 d1e80a87 编写于 作者: 邹晓航

添加avl-tree

上级 5740c723
#ifndef _AVL_TREE_H_
#define _AVL_TREE_H_
#include "Allocator.h"
namespace TinySTL{
//class of avl tree
template<class T>
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<T> 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
......@@ -86,6 +86,7 @@
<ClInclude Include="Algorithm.h" />
<ClInclude Include="Alloc.h" />
<ClInclude Include="Allocator.h" />
<ClInclude Include="AVLTree.h" />
<ClInclude Include="BinarySearchTree.h" />
<ClInclude Include="Bitmap.h" />
<ClInclude Include="CircularBuffer.h" />
......
......@@ -83,5 +83,8 @@
<ClInclude Include="BinarySearchTree.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="AVLTree.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册