private string CreatePostfixNotation() { char[] operators = new char[] { '|', '+', '-', '*', '/', '(', ')' }; operatorsStack.Push("|"); InfixNotation = InfixNotation.Replace(" ", string.Empty); InfixNotation = InfixNotation + "|"; int position = 0; while (position < InfixNotation.Length) { int length = InfixNotation.IndexOfAny(operators, position) - position; if (length == 0) { length = 1;//in case next block is operator } string block = InfixNotation.Substring(position, length); position += length; AddBlockToStacks(block); } StringBuilder result = new StringBuilder(); Stack <string> tmpStack = new Stack <string>(postfixNotationStack); foreach (var n in tmpStack) { result.Append(n); result.Append(" "); } return(result.ToString()); }