Exemple #1
0
    private void InputOperatorStack_Operator(KeyName newName)
    {
        char newOperator = CalculatorData.GetKeyValueByName(newName);
        int  newLevel    = OperatorFactory.OperatorPriority(newOperator);

        while (operatorsStack.Count != 0 &&
               operatorsStack.Peek() != CalculatorData.GetKeyValueByName(KeyName.Bracket_Left))
        {
            var oldOperator = operatorsStack.Peek();
            var oldLevel    = OperatorFactory.OperatorPriority(oldOperator);

            if (newLevel <= oldLevel)
            {
                Calculate();
            }
            else
            {
                operatorsStack.Push(newOperator);
                return;
            }
        }
        operatorsStack.Push(newOperator);
    }