v1
Brett 2023-12-20 14:45:48 -05:00
parent 665f6e0186
commit ce778da7f1
1 changed files with 10 additions and 5 deletions

View File

@ -59,9 +59,14 @@ namespace blt
ALLOC alloc; ALLOC alloc;
node* root = nullptr; 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: public:
@ -104,7 +109,7 @@ namespace blt
{ {
if (root == nullptr) if (root == nullptr)
{ {
root = new node(t); root = newNode(t);
return; return;
} }
node* search = root; node* search = root;
@ -115,7 +120,7 @@ namespace blt
{ {
if (search->left == nullptr) if (search->left == nullptr)
{ {
search->left = new node(t); search->left = newNode(t);
break; break;
} }
search = search->left; search = search->left;
@ -123,7 +128,7 @@ namespace blt
{ {
if (search->right == nullptr) if (search->right == nullptr)
{ {
search->right = new node(t); search->right = newNode(t);
break; break;
} }
search = search->right; search = search->right;