protected LinkedTree <T> Clone(int level) { LinkedTree <T> cloneTree = new LinkedTree <T>(Value); cloneTree.depth = depth; cloneTree.level = level; cloneTree.count = count; foreach (LinkedTree <T> child in childrenList) { LinkedTree <T> cloneChild = child.Clone(level + 1); cloneChild.parent = cloneTree; cloneTree.childrenList.AddLast(cloneChild); } return(cloneTree); }
public override void Remove() { if (parent == null) { return; } parent.childrenList.Remove(this); if (depth + 1 == parent.depth) { parent.UpdateDepth(); } parent.count -= count; parent.BubbleCount(-count); parent = null; }
public override void Add(Tree <T> tree) { LinkedTree <T> gtree = (LinkedTree <T>)tree; if (gtree.Parent != null) { gtree.Remove(); } gtree.parent = this; if (gtree.depth + 1 > depth) { depth = gtree.depth + 1; BubbleDepth(); } gtree.level = level + 1; gtree.UpdateLevel(); childrenList.AddLast(gtree); count += tree.Count; BubbleCount(tree.Count); }