Esempio n. 1
0
        //先假定運算符不會連續發生
        public void Add(NewBinary Operator)
        {
            //第一個運算
            if (Root.ParentNode == null)
            {
                Root.ParentNode = Node.Build()
                                  .SetLeftNode(Root)
                                  .SetOperator(Operator)
                                  .Exec();
                CurrentNode = Root.ParentNode;
                return;
            }

            //非第一個,則一直找到優先度的最高點
            Node tmp = CurrentNode;

            while (tmp.ParentNode != null &&
                   (tmp.ParentNode.value.Operator != null &&
                    tmp.ParentNode.value.Operator.Priority >= Operator.Priority))  //從底往上升,升到優先度比自己小為止
            {
                tmp = tmp.ParentNode;
            }



            //處於最高點,以及非最高點
            if (tmp.ParentNode == null)
            {
                //樹頂
                //雙向關係
                Node newParentNode = Node.Build()
                                     .SetLeftNode(tmp)
                                     .SetOperator(Operator)
                                     .Exec();
                tmp.ParentNode = newParentNode;

                CurrentNode = newParentNode;
            }
            else
            {
                //非樹頂→生出旁枝
                Node newRightNode = Node.Build()
                                    .SetParentNode(tmp.ParentNode)
                                    .SetOperator(Operator)
                                    .SetLeftNode(tmp)
                                    .Exec();
                tmp.ParentNode.RightNode = newRightNode;
                tmp.ParentNode           = newRightNode;

                CurrentNode = newRightNode;
            }
        }
Esempio n. 2
0
 public Builder SetOperator(NewBinary Operator)
 {
     this.value = new Value(Operator);
     return(this);
 }
Esempio n. 3
0
 public void Add(NewBinary Operator)
 {
     newTreeStack.Peek().Add(Operator);
 }
Esempio n. 4
0
 public Value(NewBinary Operator)
 {
     this.Operator = Operator;
     this.Number   = null;
 }
Esempio n. 5
0
 public decimal Compute(NewBinary Operator, decimal num1, decimal num2)
 {
     return(Operator.Formula(num1, num2));
 }