public Setting() { // Инцилизация стандартных операторов StandartOperators = new StandartOperator[] { new StandartOperator(operatorPlus, 0, (x, y) => x + y), new StandartOperator(operatorMinus, 0, (x, y) => x - y), new StandartOperator(operatorMultiply, 1, (x, y) => x * y), new StandartOperator(operatorShare, 1, (x, y) => x / y), new StandartOperator(operatorPow, 2, (x, y) => Math.Pow(x, y)), }; }
public static object[] Hendler(object[] InData, Setting setting) { Stack <object> resulStack = new Stack <object>(); Stack <object> BuferOperator = new Stack <object>(); foreach (var elem in InData) { if (elem.GetType() != typeof(StandartOperator) && elem.GetType() != typeof(char)) { resulStack.Push(elem); } else { StandartOperator @operator = elem as StandartOperator; if (BuferOperator.Count > 0 && !CheckChar(elem, setting.OperatorParenthesisIn)) { if (CheckChar(elem, setting.OperatorParenthesisOut)) { while (BuferOperator.Count > 0 && !CheckChar(BuferOperator.Peek(), setting.OperatorParenthesisIn)) { resulStack.Push(BuferOperator.Pop()); } BuferOperator.Pop(); continue; } else if (@operator.Priority > GetPriority(BuferOperator.Peek())) { BuferOperator.Push(@operator); } else { while (BuferOperator.Count > 0 && @operator.Priority <= GetPriority(BuferOperator.Peek())) { resulStack.Push(BuferOperator.Pop()); } BuferOperator.Push(@operator); } } else { BuferOperator.Push(elem); }