Deletion in binary search tree

后端 未结 3 442
既然无缘
既然无缘 2021-01-16 16:51

So when I delete in binary search tree, do I need to have like 7 different cases i.e.

  1. Left Leaf;
  2. Right Leaf;
  3. Left child with only left child.
3条回答
  •  礼貌的吻别
    2021-01-16 17:18

    Deleting a NULL pointer has no ill effect. So, you should be able to do this with no special cases. The basic part is just:

    delete current->left;
    delete current->right;
    

提交回复
热议问题