3
Studying BST (binary search tree) did not understand some parts of the code in the function delete of "mycodeschool".
That part of the code, more specifically:
// Case 1:  No child
    if(root->left == NULL && root->right == NULL) { 
        delete root;
        root = NULL;
    }
//Case 2: One child 
    else if(root->left == NULL) {
        struct Node *temp = root;
        root = root->right;
        delete temp;
    }
- I don’t understand why in "Case 1" - rootcan receive- NULLafter receiving the command- delete. I could just put- root=NULLand only?
- And also in "Case 2" When you delete - temp, root is also being deleted, not? since- temphas the same address as- root.
- And I also did not understand the need to delete since there is the command - root=root->right.
- And why in "Case 1" the - deletecomes before the main command- root=NULLand in "Case 2"- deleteis after the main command- root=root->right?