Example #1
0
        public Node CloneTreeTopNode()
        {
            var top = GetTop();

            var tmpTree = new ExpressionTree();

            var recursive = CloneTopNode(top);

            return(recursive);
        }
Example #2
0
        /// <summary>
        /// 計算樹的結果
        /// </summary>
        /// <param name="tree">運算樹</param>
        /// <returns>運算答案</returns>
        public decimal EvaluateTree(ExpressionTree tree)
        {
            Node top = tree.GetTop();

            if (top.NodeValue.Number.HasValue)
            {
                return(top.NodeValue.Number.Value);
            }
            decimal ans = PackNode(top).NodeValue.Number.Value;

            return(ans);
        }
Example #3
0
        /// <summary>
        /// 計算樹的結果
        /// </summary>
        /// <param name="tree">運算樹</param>
        /// <returns>運算答案</returns>
        public decimal EvaluateTree(ExpressionTree tree)
        {
            System.Diagnostics.Debug.WriteLine($"there 11");
            Node top = tree.GetTop();

            if (top.NodeValue.Number.HasValue)
            {
                return(top.NodeValue.Number.Value);
            }
            decimal ans = PackNode(top).NodeValue.Number.Value;

            return(ans);
        }
Example #4
0
        /// <summary>
        /// 加一棵子樹進來
        /// </summary>
        /// <param name="tree">子樹</param>
        public void Add(ExpressionTree tree)
        {
            //如果是第一個數字
            if (Root == null)
            {
                this.Root        = tree.Root;
                this.CurrentNode = tree.CurrentNode;
            }

            if (CurrentNode.IsOperator())
            {
                Node topNode = tree.GetTop();
                CurrentNode.RightNode = topNode;
                topNode.ParentNode    = CurrentNode;

                //主樹現有node必須是子樹的頂端
                CurrentNode = topNode;
            }

            this.LastCurrentNode = tree.GetTop();
        }