public double App(string inp) { string[] elements = GetElements(inp); Node current, currentRoot, newNode; Stack <Node> roots = new Stack <Node>(); char prevOperator = '+'; current = new RootNode(); currentRoot = current; roots.Push(currentRoot); for (int i = 0; i < elements.Length; i++)//"(2 / (2 + 3.33) * 4) - -6" { if (Operators.ContainsKey(elements[i])) { newNode = new OperatorNode { Operator = elements[i] }; if (elements[i].Last() == 'u') { current.AddOperand(newNode); } else { if (IsHigher(elements[i].First(), prevOperator)) { newNode.InsertAbowe(current); } else { newNode.InsertBelowAsFirstOperand(currentRoot); } prevOperator = elements[i][0]; } current = newNode; } else if (char.IsDigit(elements[i].First())) { newNode = new ValueNode { Value = double.Parse(elements[i]) }; current.AddOperand(newNode); current = newNode; } else { if (elements[i][0] == '(') { newNode = new RootNode(); current.AddOperand(newNode); current = newNode; roots.Push(current); currentRoot = roots.Peek(); } else if (elements[i][0] == ')') { prevOperator = '*'; roots.Pop(); currentRoot = roots.Peek(); current = currentRoot; } } } TestContext.Out.Write(currentRoot.GetString()); return(currentRoot.CalculateValue()); }