예제 #1
0
        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;
        }
예제 #2
0
        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;
        }
예제 #3
0
 public int GetTotal(TreeNode node)
 {
     _total += Root.Value;
     _GetTotal(node);
     return _total;
 }
예제 #4
0
 public override void Add(TreeNode node)
 {
     Root.Add(node);
 }
예제 #5
0
 public BinaryTree(TreeNode treeNode)
 {
     Root = treeNode;
 }
예제 #6
0
        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);
            }
        }
예제 #7
0
 public abstract void Add(TreeNode node);