private bool ContinueCompareOperators(ListStack <char> stack, char current) { if (stack.IsEmpty()) { return(false); } return(CompareOperators(stack.Peek(), current) >= 0); }
public string GetPostFix(string inFix) { ListStack <char> stack = new ListStack <char>(); char[] postFixArray = new char[inFix.Length]; int index = 0; for (var i = 0; i < inFix.Length; i = i + 1) { char current = inFix[i]; if (char.IsNumber(current)) { postFixArray[index++] = current; continue; } if (current == '(') { stack.Push(current); continue; } if (current == ')') { while (true) { char temp = stack.Pop(); if (temp == '(') { break; } postFixArray[index++] = temp; } continue; } while (ContinueCompareOperators(stack, current)) { stack.Pop(); postFixArray[index++] = stack.CurrentData; } stack.Push(current); } while (!stack.IsEmpty()) { stack.Pop(); postFixArray[index++] = stack.CurrentData; } return(new string(postFixArray).Replace('\0', ' ').Trim()); }