From 9822b8f75ba76d061ea26b43dabd9b6fbfa6d65d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Sat, 18 Oct 2014 18:40:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E6=8E=89height=E7=9A=84=E6=97=A0?= =?UTF-8?q?=E7=94=A8=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TinySTL/BinarySearchTree.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/TinySTL/BinarySearchTree.h b/TinySTL/BinarySearchTree.h index 016ccd4..78eb095 100644 --- a/TinySTL/BinarySearchTree.h +++ b/TinySTL/BinarySearchTree.h @@ -49,7 +49,7 @@ namespace TinySTL{ bool empty()const{ return root_ == 0; } size_t size()const{ return size_; } - size_t height()const{ return height_aux(root_, 0); } + size_t height()const{ return height_aux(root_); } const_iterator root(){ return const_iterator(root_, this); } const_iterator cbegin(){ return find_min(); } @@ -71,7 +71,7 @@ namespace TinySTL{ nodeAllocator::deallocate(ptr); } } - size_t height_aux(const node *p, size_t h)const; + size_t height_aux(const node *p)const; void erase_elem(const T& val, node *&ptr); void insert_elem(const T& val, node *&ptr); const_iterator find_min_aux(const node *ptr); @@ -82,11 +82,11 @@ namespace TinySTL{ void print_postorder_aux(const string& delim, std::ostream& os, const node *ptr)const; };//end of bst class template - size_t binary_search_tree::height_aux(const node *p, size_t h)const{ + size_t binary_search_tree::height_aux(const node *p)const{ if (p == 0) - return h; + return 0; else{ - return TinySTL::max(height_aux(p->left_, h), height_aux(p->right_, h)) + 1; + return TinySTL::max(height_aux(p->left_), height_aux(p->right_)) + 1; } } template