public override BinaryTree <T> Add(T value) { if (value.CompareTo(Value) == -1) { if (LeftChild.GetType() == typeof(Branch <T>)) { LeftChild.Add(value); } else { Branch <T> tempBranch = new Branch <T>(value); LeftChild = tempBranch; } } else if (value.CompareTo(Value) == 1) { if (RightChild.GetType() == typeof(Branch <T>)) { RightChild.Add(value); } else { Branch <T> tempBranch = new Branch <T>(value); RightChild = tempBranch; } } return(this); }
public void Add(T value) { if (LeftChild == null) { LeftChild = new Tree <T>(value); return; } if (RightChild == null) { RightChild = new Tree <T>(value); return; } if (LeftChild.Depth() <= RightChild.Depth()) { LeftChild.Add(value); return; } RightChild.Add(value); }
public TreeNode <T> Add(T value) { if (LeftChild == null) { LeftChild = new TreeNode <T>(value); return(LeftChild); } else if (RightChild == null) { RightChild = new TreeNode <T>(value); return(RightChild); } var ld = LeftChild.Depth(); var rd = RightChild.Depth(); if (LeftChild.Depth() <= RightChild.Depth()) { return(LeftChild.Add(value)); } return(RightChild.Add(value)); }