public void Insert(int value) { // If value greater or equal to previous. insert to the right. if (value >= data) { // If right node is null... create node if (rightNode == null) { rightNode = new TreeNode(value); } // If right node is not null... insert node after else { rightNode.Insert(value); } } else { // if value is less than current data. Insert to the left if (leftNode == null) { // if left node i null... create node leftNode = new TreeNode(value); } // If left node is not null... insert node after else { leftNode.Insert(value); } } }
public void Insert(int value) { if (value >= data) { if (RightNode == null) { RightNode = new TreeNode(value); } else { RightNode.Insert(value); } } else { if (LeftNode == null) { LeftNode = new TreeNode(value); } else { LeftNode.Insert(value); } } }
//Insert public void Insert(int data) { if (root != null) { root.Insert(data); } else { root = new TreeNode(data); } }
// Insert behaviour for the root public void Insert(int data) { // if root not null... call insert on the root node if (root != null) { root.Insert(data); } // if the root is null... Create root else { root = new TreeNode(data); } }