Binary tree issues

closed account (4EbDSL3A)
Im trying to create a binary search tree out of some numbers from an input file, the tree is being constructed however, the sizes of each node ( meaning the number of children it has) are mixed up, while some of the sizes are correct, a few are wrong, what am i doing incorrectly?


void Tree::insert(node *&root, node *&newNode){
if (root == NULL){
root = newNode;
root->size = 0;
}

else if (newNode->value < root->value){
insert(root->left,newNode);
root->size++;

}
else
insert(root->right,newNode);
root->size++;
}



void Tree::insertNode(int number){

node *newNode;

newNode = new node;

newNode->left = NULL;
newNode->right = NULL;

newNode->value = number;

insert(root,newNode);
}
Topic archived. No new replies allowed.