lundi 13 avril 2015

creation of pointer with new seems to don't work c++11

Currently I'am working on a binary search tree class just to learn the ins and out of this kind of data structures. In this class i created an insertion function to insert element in the BST recursively (code below), the problem in this function is that she does not do what she mean to do, after some tweeking with the code it seems that the node = new tree_node<data>(val); does not create the root node of the tree.



void _insert(tree_node<data> *node, data val){
if (!node){
node = new tree_node<data>(val);
return;
}
if (_comparator(val, *(node->_data)) < 0) {
_insert(node->_left_child, val);
}
else if (_comparator(val, *(node->_data)) > 0) {
_insert(node->_right_child, val);
}
else return;
}


Any suggestion or any further information that you need me to give you in order to answer my question will be my pleasure.


Aucun commentaire:

Enregistrer un commentaire