public int GetSmallestPrime(TreeNode node) { int smallest = -1; if (node.Left != null && node.Left.Value != -1) { smallest = GetSmallestPrime(node.Left); } if (smallest != -1) return smallest; if (NxqdMath.IsPrime(node.Value)) { return node.Value; } if (node.Right != null && node.Right.Value != -1) return GetSmallestPrime(node.Right); TreeNode nodeTmp = node.Parent; node.Value = -1; GetSmallestPrime(nodeTmp); return -1; }
private void _GetTotal(TreeNode node) { if (node.Left != null && node.Left.Value != -1) _GetTotal(node.Left); if (node.Right != null && node.Right.Value != -1) _GetTotal(node.Right); _total += node.Value; node.Value = -1; }
public int GetTotal(TreeNode node) { _total += Root.Value; _GetTotal(node); return _total; }
public override void Add(TreeNode node) { Root.Add(node); }
public BinaryTree(TreeNode treeNode) { Root = treeNode; }
public override void Add(TreeNode node) { if (node.Value >= Value) { if (Right == null) { Right = node; Right.Parent = this; } else Right.Add(node); } if (node.Value < Value) { if (Left == null) { Left = node; Left.Parent = this; } else Left.Add(node); } }
public abstract void Add(TreeNode node);