Allow non-default constructor objects?
parent
e5613c8007
commit
21aa7ed6ac
|
@ -26,6 +26,10 @@ namespace blt {
|
|||
BST_node* right = nullptr;
|
||||
T payload;
|
||||
|
||||
explicit BST_node(const T& _payload) {
|
||||
payload = _payload;
|
||||
}
|
||||
|
||||
~BST_node() {
|
||||
delete (left);
|
||||
delete (right);
|
||||
|
@ -52,13 +56,10 @@ namespace blt {
|
|||
continue;
|
||||
}
|
||||
// insert into the lowest node consistent with a BST
|
||||
if (element < searchNode->payload) {
|
||||
searchNode->left = new BST_node();
|
||||
searchNode->left->payload = element;
|
||||
} else {
|
||||
searchNode->right = new BST_node();
|
||||
searchNode->right->payload = element;
|
||||
}
|
||||
if (element < searchNode->payload)
|
||||
searchNode->left = new BST_node(element);
|
||||
else
|
||||
searchNode->right = new BST_node(element);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -114,8 +115,7 @@ namespace blt {
|
|||
|
||||
inline void insert(const T& element) {
|
||||
if (m_root == nullptr) {
|
||||
m_root = new BST_node();
|
||||
m_root->payload = element;
|
||||
m_root = new BST_node(element);
|
||||
return;
|
||||
}
|
||||
insert(m_root, element);
|
||||
|
|
Loading…
Reference in New Issue