public string HienThiThuTuPhepTinh() { List <string> DanhSach = DanhSachThuTu.ToList(); DanhSach.Reverse(); string thutu = ""; foreach (var item in DanhSach) { thutu = thutu + " " + item; } return(thutu); }
private double CalculateAnswer() { //if (m_PolishStack.Count <= 1) return; TokenReader PolishTokenReader = new TokenReader(); string m_CombinedInfixString = m_InfixString; if (m_NumberString != "") { m_CombinedInfixString += m_NumberString + ' '; } List <string> polishTokenList = m_PolishStack.ToList(); List <string> infixStringArray = m_CombinedInfixString.Split(' ').ToList(); infixStringArray.RemoveAll(IsEmptySpace); infixStringArray.RemoveAt(infixStringArray.Count - 1); string rpnString = ConvertInfixToRPN(infixStringArray.ToArray()); List <string> rpnDisplayString = rpnString.Split(' ').ToList(); rpnDisplayString.Reverse(); //rpnDisplayString.RemoveAt(rpnDisplayString.Count - 1); rpnDisplayString.RemoveAt(0); debugBox.Text = rpnString; string stackRpnString = ""; foreach (string token in polishTokenList) { stackRpnString += token + " "; } //debugBox.Text = stackRpnString + Environment.NewLine + m_sInfixString; ICalculationExpression resultExpression = null; try { resultExpression = PolishTokenReader.ReadToken(rpnDisplayString); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } ResetInputString(); BuildCalculationString(); double result = 0.0; if (resultExpression != null) { string resultString = "Infinity?"; try { result = resultExpression.Interpret(); resultString = result.ToString(); } catch (NullReferenceException exception) { Console.WriteLine(exception.Message); } calcResultLabel.Text = resultString; } else { calcResultLabel.Text = "Error"; //ClearCalculations(); Console.WriteLine("Error: resultExpression is a 'null' object"); } return(result); }