views:

222

answers:

1

i created a binary tree with some integer values ...i can search the tree by my code ,but i dont know how to proceed delete node operation ..help me with simple program using c..thanks in advance.......

+1  A: 

Wikipedia entry - Binary Search Tree - explains how to implement BST operations.

Deletion: There are several cases to be considered:

  • Deleting a leaf: Deleting a node with no children is easy, as we can simply remove it from the tree.
  • Deleting a node with one child: Delete it and replace it with its child.
  • Deleting a node with two children: Call the node to be deleted "N". Do not delete N. Instead, choose either its in-order successor node or its in-order predecessor node, "R". Replace the value of N with the value of R, then delete R. (Note: R itself has up to one child.)
Nick D