From 6be63f791c3eaf1e63b75bc5acc945783dc1ed4e 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, 29 Nov 2014 16:15:26 +0800 Subject: [PATCH] bug fix --- TinySTL/BinarySearchTree.h | 7 ++++--- TinySTL/List.h | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/TinySTL/BinarySearchTree.h b/TinySTL/BinarySearchTree.h index d7e8ebc..ddd789c 100644 --- a/TinySTL/BinarySearchTree.h +++ b/TinySTL/BinarySearchTree.h @@ -144,9 +144,10 @@ namespace TinySTL{ void binary_search_tree::insert_elem(const T& val, node *&ptr){//重复的元素不插入 if (ptr == 0){ ptr = nodeAllocator::allocate(); - memset(ptr, 0, sizeof(node)); - ptr->data_ = val; - //ptr->left_ = ptr->right_ = 0; + construct(&(ptr->data_, val)); + /*memset(ptr, 0, sizeof(node)); + ptr->data_ = val;*/ + ptr->left_ = ptr->right_ = 0; ++size_; } else{ diff --git a/TinySTL/List.h b/TinySTL/List.h index bb217d7..8c0c8b4 100644 --- a/TinySTL/List.h +++ b/TinySTL/List.h @@ -154,7 +154,8 @@ namespace TinySTL{ nodePtr newNode(const T& val = T()){ nodePtr res = nodeAllocator::allocate(); res->container = this; - res->data = val; + //res->data = val; -> bug + construct(&(res->data), val);//fix res->prev = nullptr; res->next = nullptr; return res;