'How to deletenode from BinaryTree?
I tried to write a method to delete Node from BinaryTree from my understanding.
is that method is true or not?!
public void deleteNode(TreeNode oldNode, TreeNode current) {
if(oldNode.data != current.data) {
System.out.print("Error");
return;
}
if(oldNode.data == current.data) {
current = null;
System.out.print("Delete succesfully ");
return;
}
if(oldNode.data > current.data) {
deleteNode(oldNode,current.right);
}
if(oldNode.data < current.data) {
deleteNode(oldNode,current.left);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
