I'm trying to complete the code for BST ..I'm finding trouble with the delete function ..
input :: integer
process :: deletes the node containing that integer
output :: void
i've to consider the following cases :
1 - node is the root .. therefore I've to delete it (no parents)
2 - node has only one child .. therefore I've to link it with child and delete it
3 - node has two children .. therefore I've to do two things
(i) find the replacement ( easy : go one step left then many steps right untill NULL is found and its value is stored in original node value )
(ii) set the pointer pointing to the replacement to NULL (can't do)
can anyone help me ??
I've searched many books including data structures but couldn't find an answer.
if anyone already written the code paste it here (even without commenting) and i will understand it.
Take a pointer "prev" to the root node. Do a depth-first search until
prev->left or prev->right is equal to the pointer passed to your function.
Now prev points to the parent of the node you want to delete.