i'm trying to implement my own binary search tree, i've stucked on inserting data, can you explain me what i'm doing wrong .
void tree::add(int data) {
tree * tmp = new tree;
if (root == NULL) {
root = tmp;
root->data = data;
root->left = NULL;
root->right = NULL;
}
else if (data <= root->data) {
left = tmp;
left->data = data;
left->left = NULL;
left->right = NULL;
while (tmp != NULL) {
if (data <= left->data) {
tmp = left->left;
} else {
tmp = left->right;
}
}
}
I'm trying to fill left node, if data i smaller than root but if data is greater than this leaf but still smaller than root it should be right child, but actually i have access volation