binary search tree - BST on c++ error -
i tried create bst on cpp done class node in class tree because it's logical. header:
class node; class tree { public: node* root; tree(); tree(int val); void insert(int val); class node { public: node(); node(int val); node* right; node* left; int val; }; };
implamation:
tree::tree() { this->root = null; } tree::node::node() { } tree::node::node(int val) { this->val = val; this->left = null; this->right = null; } void tree::insert(int val) { this->root = new node(3); }
i got error on
this->root = new node(3); intellisense: value of type "tree::node *" cannot assigned entity of type "node *" error c2440 : '=' : cannot convert 'tree::node *' 'node *'
what did done wrong please? root node* , new node (3) return node* problem? thanks!!!
to understanding, in current implementation, declaring 2 classes name node
; 1 in global scope while other 1 in scope of class tree
. can solved using 1 class.
Comments
Post a Comment