From ce778da7f1ba4ece4dfd4e5b36f84d9633da4cf5 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Wed, 20 Dec 2023 14:45:48 -0500 Subject: [PATCH] bin tree --- include/blt/std/binary_tree.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/include/blt/std/binary_tree.h b/include/blt/std/binary_tree.h index 8e6267a..60775fb 100755 --- a/include/blt/std/binary_tree.h +++ b/include/blt/std/binary_tree.h @@ -59,9 +59,14 @@ namespace blt ALLOC alloc; node* root = nullptr; - node* newNode(const T& t) + inline node* newNode(const T& t) { - return alloc.allocate(1); + return alloc.construct(alloc.allocate(1), t); + } + + inline node* newNode(T&& t) + { + return alloc.construct(alloc.allocate(1), t); } public: @@ -104,7 +109,7 @@ namespace blt { if (root == nullptr) { - root = new node(t); + root = newNode(t); return; } node* search = root; @@ -115,7 +120,7 @@ namespace blt { if (search->left == nullptr) { - search->left = new node(t); + search->left = newNode(t); break; } search = search->left; @@ -123,7 +128,7 @@ namespace blt { if (search->right == nullptr) { - search->right = new node(t); + search->right = newNode(t); break; } search = search->right;