/// <summary> /// Determines the depth of the next vacant position in the tree /// </summary> /// <returns></returns> public int Depth() { if (LeftChild == null || RightChild == null) { return(0); } return(1 + Math.Max(LeftChild.Depth(), RightChild.Depth())); }
public void Add(T value) { if (LeftChild == null) { LeftChild = new DemoTree1 <T>(value); } else if (RightChild == null) { RightChild = new DemoTree1 <T>(value); } else if (LeftChild.Depth() < RightChild.Depth()) { LeftChild.Add(value); } else { RightChild.Add(value); } }
public void Add(T value) { if (LeftChild == null) { LeftChild = new DemoTree <T>(value); return; } if (RightChild == null) { RightChild = new DemoTree <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)); }