public void Add(IBinaryTreeNode <TItem> node) { if (Item.CompareTo(node.Item) > 0) { if (LeftNode == null) { LeftNode = node; } else { LeftNode.Add(node); } } else if (Item.CompareTo(node.Item) < 0) { if (RightNode == null) { RightNode = node; } else { RightNode.Add(node); } } }
public void Add(T value) { if (value.Equals(Value)) { if (RightNode != null) { RightNode = new Node <T>(value); } else { RightNode.Add(value); } } else { if (LeftNode != null) { LeftNode.Add(value); } else { LeftNode = new Node <T>(value); } } }
public void Add(int value) { //Should go left if (value < Value) { if (LeftNode == null) { LeftNode = new Node(this, value); } else { LeftNode.Add(value); } } else if (value >= Value) { //Value is greater or equal add right node if (RightNode == null) { RightNode = new Node(this, value); } else { RightNode.Add(value); } } }
public void Add(int data, int rank) { var node = new TreeNode(data); node.Rank = rank; if (node.Value.CompareTo(Value) == -1) { if (LeftNode == null) { node.Rank += 1; LeftNode = node; } else { LeftNode.Add(data, rank + 1); } } else { if (RightNode == null) { node.Rank += 1; RightNode = node; } else { RightNode.Add(data, rank + 1); } } }