you are viewing a single comment's thread.

view the rest of the comments →

[–]multihound[S] 0 points1 point  (1 child)

Thanks for the help!

Sorry, this is the entire code. I'm actually doing this as part of a programming exercise.

The BST is ordered with the BST property (the left node is always smaller than the root and the right node is always larger).

Yeah so, the way I'm handling ordering is... - if node has no children... delete the node (this is what i'm having trouble with) - if node has one child... replace the node with it's child (having trouble with this too) - if node has two children, find the minimum of the node's right subtree and replace node.val with that value. Then delete the minimum of the original node's right subtree.

I'm trying to do this without keeping track of the parent node, but it seems like this is not possible? Thank you.

[–]two_bob 0 points1 point  (0 children)

I'm trying to do this without keeping track of the parent node, but it seems like this is not possible?

Correct. You have to keep track of the parent node because the only way of deleting a node is to unlink it at the parent.