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;