public List<OperationElement> GetOperationElements(string expression) { if (string.IsNullOrEmpty(expression)) throw new EmptyStringException(); var operationElements = new List<OperationElement>(); var builder = new StringBuilder(); foreach (char character in expression) { if (char.IsDigit(character)) { builder.Append(character); } else if (IsOperator(character)) { if (builder.Length != 0) { operationElements.Add(new OperationElement(OperationElementType.Number, builder.ToString())); builder.Clear(); } operationElements.Add(new OperationElement(OperationElementType.Operator, character.ToString())); } else { throw new IncorrectOperationStringException(expression); } } if (builder.Length != 0) operationElements.Add(new OperationElement(OperationElementType.Number, builder.ToString())); return operationElements; }
public IList<string> Parse(string expression) { if (!Validate(expression)) throw new ArgumentException("Invalid expresion", "expression"); const string left = "left"; const string @operator = "operator"; const string right = "right"; const string pattern = @"^\s*(?<left>\d+)\s*((?<operator>(\+|\-|\*|\/))\s*(?<right>.*)\s*){0,1}$"; var parsedExpression = new List<string>(); string operatorText; do { var match = Regex.Match(expression, pattern, RegexOptions.IgnorePatternWhitespace); var leftText = match.Groups[left].Value; operatorText = match.Groups[@operator].Value; expression = match.Groups[right].Value; parsedExpression.Add(leftText); if (!string.IsNullOrEmpty(operatorText)) parsedExpression.Add(operatorText); } while (!string.IsNullOrEmpty(operatorText)); return parsedExpression; }
public MathsCalculator() { operations = new List<Operation>(); operations.Add(new Addition()); operations.Add(new Subtraction()); operations.Add(new Multiplication()); operations.Add(new Division()); }
public void Initialize() { if (mInitialized) { return; } mValues = new List<AValue>(); mVariables = new List<Variable> (); //Retrieve all child values foreach (AValue v in GetComponentsInChildren<AValue>()) { mValues.Add (v); v.SetParentContainer (this); } //Retrieve all child variables (which are also values but may be accessed specifically foreach (Variable v in GetComponentsInChildren<Variable>()) { mVariables.Add (v); } //Set self being to all formulas foreach (IHasFormula f in GetComponentsInChildren<IHasFormula>()) { f.Initialize(); } mInitialized = true; }
public List<string> getAvialableOperators() { var operatorList = new List<string>(); foreach (var op in operators) operatorList.Add(op.Key); return operatorList; }
public Form1() { InitializeComponent(); resultBox.Text = ""; buttons.Add(button0); buttons.Add(button1); buttons.Add(button2); buttons.Add(button3); buttons.Add(button4); buttons.Add(button5); buttons.Add(button6); buttons.Add(button7); buttons.Add(button8); buttons.Add(button9); // ------------------------------------------------------------------------ var rem1 = from i in numbers where i > 80 select i; // ------------------------------------------------------------------------ // ------------------------------------------------------------------------ List<int> iHolder = new List<int>(); foreach(int i in numbers) { if(i > 80) { iHolder.Add(i); } } var rem2 = iHolder; // ------------------------------------------------------------------------- }
public List<int> Calculate2() { List<HomeWork> lhwc = new List<HomeWork>(); for (int a = 1; a <= 11; a++) { lhwc.Add(new HomeWork() { Id = a, Cost = a, Revenue = 10 + a, SellPrice = 20 + a }); } return Calculation_results(4, "1", lhwc); }
public static IEnumerable<Symbol> CreateWhiteSpace(int amount) { List<Symbol> ws = new List<Symbol>(); for (int i=0; i<amount; i++) { ws.Add(new WhiteSpace()); } return (IEnumerable<Symbol>)ws; }
public List<int> Calculation_results(int GCount, string DType, List<HomeWork> lhwc) { List<int> strAns = new List<int>(); //GCount 可以是3筆一組、4筆一組、甚至是任意決定幾筆一組 int txtCount = GCount; //DType 為指定欄位參數 string txtddlType = DType; int Total = 0; for (int b = 0; b < lhwc.Count; b++) { switch (txtddlType) { case "0": Total += lhwc[b].Cost; break; case "1": Total += lhwc[b].Revenue; break; case "2": Total += lhwc[b].SellPrice; break; } if (b != lhwc.Count - 1) { if (lhwc[b].Id % txtCount == 0) { strAns.Add(Total); Total = 0; } } else { strAns.Add(Total); } } return strAns; }
public string[] ConvertToPostfixNotation(string input) { List<string> operators = new List<string>(standart_operators); List<string> outputSeparated = new List<string>(); Stack<string> stack = new Stack<string>(); foreach (string c in Separate(input)) { if (operators.Contains(c)) { if (stack.Count > 0 && !c.Equals("(")) { if (c.Equals(")")) { string s = stack.Pop(); while (!s.Equals("(")) { outputSeparated.Add(s); s = stack.Pop(); } } else if (GetPriority(c) > GetPriority(stack.Peek())) stack.Push(c); else { while (stack.Count > 0 && GetPriority(c) <= GetPriority(stack.Peek())) outputSeparated.Add(stack.Pop()); stack.Push(c); } } else stack.Push(c); } else outputSeparated.Add(c); } if (stack.Count > 0) foreach (string c in stack) outputSeparated.Add(c); return outputSeparated.ToArray(); }
// clear last equation in history and update text file private void btnClear_Click(object sender, EventArgs e) { if (lstLoad.Items.Count > 0) { lstLoad.Items.RemoveAt(lstLoad.Items.Count - 1); } List<string> update = new List<string>(); foreach (string s in lstLoad.Items) { update.Add(s); } HistoryDB.Update(update); }
// read text file to show history in frmHistory public static List<string> Read() { List<string> equations = new List<string>(); using (StreamReader textIn = new StreamReader(new FileStream(path, FileMode.OpenOrCreate, FileAccess.Read))) { while (textIn.Peek() != -1) { string eq = textIn.ReadLine(); equations.Add(eq); } textIn.Close(); } return equations; }
private static List<string> GetDelimitersCollection(string delimitersString) { var delimiterCollectionRegex = new Regex(@"\[(.+?)]"); ; var delimiters = new List<string>(); MatchCollection mc = delimiterCollectionRegex.Matches(delimitersString); if (mc.Count > 0) { foreach (Match m in mc) { for (int i = 0; i < m.Groups.Count; i++) { delimiters.Add(m.Groups[i].Value); } } } else { delimiters.Add(delimitersString); } return delimiters; }
public CalculatorStack(string input) { char[] delimiters = {' '}; string[] tokensArray = input.Split(delimiters); valuesList = new List<double>(); operatorsList = new List<string>(); foreach (string token in tokensArray) { if (isNumber(token)) valuesList.Add(Convert.ToDouble(token)); else if (isOperator(token)) operatorsList.Add(token); else errorCode = (int)ErrorCodes.InvalidInput; } }
public List<string> StringInterpreter(string equation) { int x = 1; List<string> list = new List<string>() { }; Regex regex = new Regex(@"(\d*\.?\d*)"); Regex regex1 = new Regex(@"[*+/-]"); MatchCollection matches = regex.Matches(equation); MatchCollection matches1 = regex1.Matches(equation); foreach (Match match in matches) { list.Add(Convert.ToString(match)); } foreach (Match match in matches1) { list.Insert(x, Convert.ToString(match)); x += 3; } return list; }
public void CalculateThis() { Console.WriteLine("What is your equation"); string equation = Console.ReadLine(); decimal number; string multiply = "*"; string add = "+"; NumSets = new List<string>(); if (decimal.TryParse(equation, out number)) { newNumb += number; } else/* if(equation == multiply)*/ { Console.WriteLine("Enter a valid Number!! \n"); CalculateThis(); } NumSets.Add(newNumb); Console.WriteLine(newNumb); }
public List<Dictionary<string, string>> Run(List<Dictionary<string, string>> PostBody) { List<Dictionary<string, string>> oResultBody = new List<Dictionary<string, string>>(); if ((PostBody != null) && (PostBody.Count > 0)) { int nFirstValue = 0; int nSecondValue = 0; Dictionary<string, string> oValues = PostBody[0]; if (oValues.ContainsKey("FirstValue")) { try { nFirstValue = Convert.ToInt32(oValues["FirstValue"]); } catch (Exception ex) {} } if (oValues.ContainsKey("SecondValue")) { try { nSecondValue = Convert.ToInt32(oValues["SecondValue"]); } catch (Exception ex) { } } int nResultValue = nFirstValue * nSecondValue; Dictionary<string, string> oResult = new Dictionary<string, string>(); oResult["Result"] = Convert.ToString(nResultValue); oResultBody.Add(oResult); } return oResultBody; }
public void numberButtonClick(object sender, EventArgs e) { List<string> values = new List<string>(); TextView textView = FindViewById<TextView> (Resource.Id.textView); cu.digitEntered = true; //cu.Eqpressed = true; cu.Num_Pressed = true; if ((textView.Text == "0") || (cu.operatorClicked) || (cu.Eqpressed)||(cu.UopClicked)) textView.Text = null; cu.operatorClicked = false; cu.UopClicked = false; cu.Eqpressed = false; if (sender.ToString() == ".") { if (!textView.Text.Contains (".")) { textView.Text += sender.ToString (); history.Add (sender.ToString ()); } else return; } else { digit = sender.ToString (); textView.Text += digit; history.Add (sender.ToString ()); } if ((sender.ToString()=="(")||(textView.Text == "(")){ do{ values.Add (sender.ToString()); }while(sender.ToString() == ")"); } }
public static List<List<Point>> GetPointSegments(List<Point> points, double yMin, double yMax) { var rv = new List<List<Point>>(); List<Point> currentList = null; for (int itemCheck = 0; itemCheck < points.Count; itemCheck++) { var point = points[itemCheck]; if (point.Y >= yMin && point.Y <= yMax) { if (currentList == null) { currentList = new List<Point>(); if (itemCheck > 0) { currentList.Add(points[itemCheck - 1]); } currentList.Add(point); } if (itemCheck < points.Count - 1) { currentList.Add(points[itemCheck + 1]); } } else { if (currentList != null) { rv.Add(currentList); } currentList = null; } } if (currentList != null) { rv.Add(currentList); } return rv; }
private static List<IToken> TokenizeInfixExpression( string infixExpressionStr ) { var tokenizedExpression = new List<IToken>(); foreach( var tokenStr in Regex.Split( infixExpressionStr, @"([-+*/%^()])" ) ) { if( string.IsNullOrWhiteSpace( tokenStr ) == false ) tokenizedExpression.Add( Token.Make( tokenStr ) ); } return tokenizedExpression; }
public void Initialize () { if (mIsInitialized) { return; } mInOuts = new List<InOutVariable> (); foreach (InOutVariable input in Inputs) { input.IsOutput = false; mInOuts.Add (input); } foreach (InOutVariable output in Outputs) { output.IsOutput = true; mInOuts.Add (output); } Debug.Assert (mInOuts.Count >= 1, "Transformation " + Error.Hierarchy (this) + " has no input nor outputs."); foreach (InOutVariable v in mInOuts) { v.SetParent (this); v.Formula = new FloatFormula (); v.Formula.Initialize (v); Debug.Assert (v.Destination == BEING_KEY.SELF || v.Destination == BEING_KEY.TARGET, "Error initializing Transformation " + Error.Hierarchy (this) + ". Only self and target destinations are allowed."); } mIsInitialized = true; }
void MakePostFix(ref List<CALCULATOR_TOKEN> listToken, ref List<CALCULATOR_TOKEN> listPostFix) { //후위 표기식으로 변환한다. Stack<CALCULATOR_TOKEN> stackTemp = new Stack<CALCULATOR_TOKEN>(); foreach (CALCULATOR_TOKEN token in listToken) { if (token.nPrecedence == (int)PRECEDENCE.OPERAND) { listPostFix.Add(token); } else { while(stackTemp.Count != 0) { CALCULATOR_TOKEN tempToken = stackTemp.Pop(); if ((int)token.nPrecedence < (int)tempToken.nPrecedence) { listPostFix.Add(tempToken); } else { //우선순위가 낮은것을 만나면, tempToken을 다시 스택에 넣어주고, 자기자신도 넣는다. stackTemp.Push(tempToken); stackTemp.Push(token); break; } } //stackTemp에는 오퍼레이터만 들어가 있으니까 스택이 비면 자기를 넣어 준다. if (stackTemp.Count == 0) { stackTemp.Push(token); } } } //이제 오퍼레이터들을 넣어 준다. foreach (CALCULATOR_TOKEN token in stackTemp) { listPostFix.Add(token); } // 후위 표기식 완료 한번 뿌려보자 Debug.WriteLine("후위 표기식 변환 확인"); foreach (CALCULATOR_TOKEN trace in listPostFix) { Debug.WriteLine("value : " + trace.strValue + " precedencd : " + trace.nPrecedence); } }
static void Main(string[] args) { double arg1, arg2; char operation; int accuracy = Config.GetAccuracy(); IStorage storage = new TextFileStorage(); List<IOperator> listop = new List<IOperator>(); listop.Add(new PlusOperator()); listop.Add(new MinusOperator()); var calc = new MegaCalculator(accuracy, storage, listop); calc.RemoveOperator('-'); string pattern = @"^(\s+)?(\-)?\d+(,\d+)?(\s+)?(\+|-|\*|/)(\s+)?(\-)?\d+(,\d+)?(\s+)?$"; Console.WriteLine("Hello. This is CALCULATOR. It takes 2 operands and performs +-/* operations. You can adjust operation accuracy with the help of app.config file. For exit use Esc key"); while (true) { Console.WriteLine("\nPress 'w' to write results to a file"); Console.WriteLine("Press 's' to show recorded results"); Console.WriteLine("Press 'q' to exit"); Console.WriteLine("Input format:'operand'_'operation'_ 'operand'. Example: -1,11111 + 1\n"); Console.Write(">"); string input = Console.ReadLine(); if (Regex.IsMatch(input, pattern)) { char[] delimiters = { ' ' }; input = Regex.Replace(input, @"\s+", " "); string[] words = input.Split(delimiters); try { arg1 = Convert.ToDouble(words[0]); operation = Convert.ToChar(words[1]); arg2 = Convert.ToDouble(words[2]); calc.AddExpression(arg1, arg2, operation); } catch (FormatException e) { Console.WriteLine(e.ToString()); } catch (OverflowException e) { Console.WriteLine(e.ToString()); } } else { if (input.Equals("w")) { storage.Save(calc.GetHistory()); continue; } if (input.Equals("s")) { calc.ShowHistoryOnConsole(); continue; } if (input.Equals("q")) { Environment.Exit(1); } Console.WriteLine("Wrong input"); } } }
void MakeList(ref List<CALCULATOR_TOKEN> listToken, string strText) { //일단.. 오퍼랜드를 구분해준다. char[] delimiter = { '+', '-', '*', '/' }; string[] operand = strText.Split(delimiter); //기존 문자열에서 오퍼랜드를 찾고, + 1 위치에 오퍼레이터가 있을 것이다. //오퍼레이터를 찾아서 순서대로 결과를 리스트에 넣어 준다. int nStartPos = 0; foreach (string op in operand) { int nFindIndex = strText.IndexOf(op, nStartPos); if (nFindIndex < 0) { //못찾는 경우도 있을려나... break; } nStartPos = nFindIndex + op.Length; listToken.Add(new CALCULATOR_TOKEN(op, (int)PRECEDENCE.OPERAND)); //정상적인 수식이라면, 마지막에는 오퍼레이터가 없다. 있으면 오류이기는 한데.. 흠.. if (nStartPos < strText.Length) { string findoperator = strText.Substring(nStartPos, 1); listToken.Add(new CALCULATOR_TOKEN(findoperator, GetPrecedence(findoperator))); } } //정상적으로 들어 갔는지 뿌려보자. foreach (CALCULATOR_TOKEN trace in listToken) { Debug.WriteLine("value : " + trace.strValue+ " precedencd : " + trace.nPrecedence ); } }
public Scanner() { Regex regex; Patterns = new Dictionary<TokenType, Regex>(); Tokens = new List<TokenType>(); LookAheadToken = null; Skipped = new List<Token>(); SkipList = new List<TokenType>(); SkipList.Add(TokenType.WHITESPACE); regex = new Regex(@"true|false", RegexOptions.Compiled); Patterns.Add(TokenType.BOOLEANLITERAL, regex); Tokens.Add(TokenType.BOOLEANLITERAL); regex = new Regex(@"[0-9]+(UL|Ul|uL|ul|LU|Lu|lU|lu|U|u|L|l)?", RegexOptions.Compiled); Patterns.Add(TokenType.DECIMALINTEGERLITERAL, regex); Tokens.Add(TokenType.DECIMALINTEGERLITERAL); regex = new Regex(@"([0-9]+\.[0-9]+([eE][+-]?[0-9]+)?([fFdDMm]?)?)|(\.[0-9]+([eE][+-]?[0-9]+)?([fFdDMm]?)?)|([0-9]+([eE][+-]?[0-9]+)([fFdDMm]?)?)|([0-9]+([fFdDMm]?))", RegexOptions.Compiled); Patterns.Add(TokenType.REALLITERAL, regex); Tokens.Add(TokenType.REALLITERAL); regex = new Regex(@"0(x|X)[0-9a-fA-F]+", RegexOptions.Compiled); Patterns.Add(TokenType.HEXINTEGERLITERAL, regex); Tokens.Add(TokenType.HEXINTEGERLITERAL); regex = new Regex(@"\""(\""\""|[^\""])*\""", RegexOptions.Compiled); Patterns.Add(TokenType.STRINGLITERAL, regex); Tokens.Add(TokenType.STRINGLITERAL); regex = new Regex(@"[a-zA-Z_][a-zA-Z0-9_]*(?=\s*\()", RegexOptions.Compiled); Patterns.Add(TokenType.FUNCTION, regex); Tokens.Add(TokenType.FUNCTION); regex = new Regex(@"[a-zA-Z_][a-zA-Z0-9_]*(?!\s*\()", RegexOptions.Compiled); Patterns.Add(TokenType.VARIABLE, regex); Tokens.Add(TokenType.VARIABLE); regex = new Regex(@"(?i)pi|e", RegexOptions.Compiled); Patterns.Add(TokenType.CONSTANT, regex); Tokens.Add(TokenType.CONSTANT); regex = new Regex(@"{\s*", RegexOptions.Compiled); Patterns.Add(TokenType.BRACEOPEN, regex); Tokens.Add(TokenType.BRACEOPEN); regex = new Regex(@"\s*}", RegexOptions.Compiled); Patterns.Add(TokenType.BRACECLOSE, regex); Tokens.Add(TokenType.BRACECLOSE); regex = new Regex(@"\(\s*", RegexOptions.Compiled); Patterns.Add(TokenType.BRACKETOPEN, regex); Tokens.Add(TokenType.BRACKETOPEN); regex = new Regex(@"\s*\)", RegexOptions.Compiled); Patterns.Add(TokenType.BRACKETCLOSE, regex); Tokens.Add(TokenType.BRACKETCLOSE); regex = new Regex(@",", RegexOptions.Compiled); Patterns.Add(TokenType.COMMA, regex); Tokens.Add(TokenType.COMMA); regex = new Regex(@"\+\+", RegexOptions.Compiled); Patterns.Add(TokenType.PLUSPLUS, regex); Tokens.Add(TokenType.PLUSPLUS); regex = new Regex(@"--", RegexOptions.Compiled); Patterns.Add(TokenType.MINUSMINUS, regex); Tokens.Add(TokenType.MINUSMINUS); regex = new Regex(@"\|\|", RegexOptions.Compiled); Patterns.Add(TokenType.PIPEPIPE, regex); Tokens.Add(TokenType.PIPEPIPE); regex = new Regex(@"&&", RegexOptions.Compiled); Patterns.Add(TokenType.AMPAMP, regex); Tokens.Add(TokenType.AMPAMP); regex = new Regex(@"&(?!&)", RegexOptions.Compiled); Patterns.Add(TokenType.AMP, regex); Tokens.Add(TokenType.AMP); regex = new Regex(@"\^", RegexOptions.Compiled); Patterns.Add(TokenType.POWER, regex); Tokens.Add(TokenType.POWER); regex = new Regex(@"\+", RegexOptions.Compiled); Patterns.Add(TokenType.PLUS, regex); Tokens.Add(TokenType.PLUS); regex = new Regex(@"-", RegexOptions.Compiled); Patterns.Add(TokenType.MINUS, regex); Tokens.Add(TokenType.MINUS); regex = new Regex(@"=", RegexOptions.Compiled); Patterns.Add(TokenType.EQUAL, regex); Tokens.Add(TokenType.EQUAL); regex = new Regex(@":=", RegexOptions.Compiled); Patterns.Add(TokenType.ASSIGN, regex); Tokens.Add(TokenType.ASSIGN); regex = new Regex(@"!=|<>", RegexOptions.Compiled); Patterns.Add(TokenType.NOTEQUAL, regex); Tokens.Add(TokenType.NOTEQUAL); regex = new Regex(@"!", RegexOptions.Compiled); Patterns.Add(TokenType.NOT, regex); Tokens.Add(TokenType.NOT); regex = new Regex(@"\*", RegexOptions.Compiled); Patterns.Add(TokenType.ASTERIKS, regex); Tokens.Add(TokenType.ASTERIKS); regex = new Regex(@"/", RegexOptions.Compiled); Patterns.Add(TokenType.SLASH, regex); Tokens.Add(TokenType.SLASH); regex = new Regex(@"%", RegexOptions.Compiled); Patterns.Add(TokenType.PERCENT, regex); Tokens.Add(TokenType.PERCENT); regex = new Regex(@"\?", RegexOptions.Compiled); Patterns.Add(TokenType.QUESTIONMARK, regex); Tokens.Add(TokenType.QUESTIONMARK); regex = new Regex(@".", RegexOptions.Compiled); Patterns.Add(TokenType.POINT, regex); Tokens.Add(TokenType.POINT); regex = new Regex(@"<=", RegexOptions.Compiled); Patterns.Add(TokenType.LESSEQUAL, regex); Tokens.Add(TokenType.LESSEQUAL); regex = new Regex(@">=", RegexOptions.Compiled); Patterns.Add(TokenType.GREATEREQUAL, regex); Tokens.Add(TokenType.GREATEREQUAL); regex = new Regex(@"<(?!>)", RegexOptions.Compiled); Patterns.Add(TokenType.LESSTHAN, regex); Tokens.Add(TokenType.LESSTHAN); regex = new Regex(@">", RegexOptions.Compiled); Patterns.Add(TokenType.GREATERTHAN, regex); Tokens.Add(TokenType.GREATERTHAN); regex = new Regex(@":", RegexOptions.Compiled); Patterns.Add(TokenType.COLON, regex); Tokens.Add(TokenType.COLON); regex = new Regex(@"^$", RegexOptions.Compiled); Patterns.Add(TokenType.EOF, regex); Tokens.Add(TokenType.EOF); regex = new Regex(@"\s+", RegexOptions.Compiled); Patterns.Add(TokenType.WHITESPACE, regex); Tokens.Add(TokenType.WHITESPACE); }
// auxiliary function public static List<int> findAllIndexInsideString(string text, string pattern) { List<int> inst = new List<int>(); int index = 0; while (index >= 0) { index = text.IndexOf(pattern, index); if(index == -1) return inst; inst.Add(index); index++; } return inst; }
private void AddPoint(double x, double y, List<Point> points) { if (double.IsNaN(y)) { return; } points.Add(new Point( ScaleCordinates( this.xMin, this.xMax, x, this.CanvasDimensions.X), ScaleCordinates( this.yMin, this.yMax, y, this.CanvasDimensions.Y))); }
public List<AValue> GetAllBindedValues() { Debug.Assert (mIsInitialized, "Calling GetAllBindedValues on a non-initialized formula on component " + Error.Hierarchy(mParent.GetComponent())); List<AValue> bindedValues = new List<AValue> (); foreach (Parameter p in mParameters.Values) { if (p.bindedValue != null) { bindedValues.Add (p.bindedValue); } } return bindedValues; }
protected double[] PrepareParameterValueList () { Debug.Assert (mIsInitialized, "Calling PrepareParameters on a non-initialized formula on component " + Error.Hierarchy(mParent.GetComponent())); List<double> parameterValueList = new List<double> (); foreach (Parameter p in mParameters.Values) { parameterValueList.Add (p.bindedValue.GetValue ()); } return parameterValueList.ToArray (); }
public static string[] ConvertToReversePolishNotation(string input) { var output = new List<string>(); var stack = new MyStack<string>(); int startOfNum = 1; bool isNumStarted = false; int counter = 0; int lnth = 0; int opBrackets = 0; int clBrackets = 0; foreach (var i in input) { switch (i) { case '(': opBrackets++; break; case ')': clBrackets++; break; } } if (opBrackets != clBrackets) { throw new InvalidOperationException("Brackets error"); } bool prevOperator = false; foreach (var i in input) { if (Char.IsDigit(i) && !isNumStarted) { prevOperator = false; isNumStarted = true; startOfNum = counter; lnth++; } if (!Char.IsDigit(i) && isNumStarted) { string number = input.Substring(startOfNum, lnth - 1); output.Add(number); isNumStarted = false; lnth = 0; } if (Char.IsDigit(i) && isNumStarted) { lnth++; } if (counter == input.Length - 1 && isNumStarted) { string number = input.Substring(startOfNum, lnth - 1); output.Add(number); isNumStarted = false; lnth = 0; } if (Operators.Contains(i.ToString())) { if (i.ToString() == "(") { prevOperator = false; stack.Push(i.ToString()); } if (i.ToString() == ")") { prevOperator = false; while (stack.Top.Object != "(") { output.Add(stack.Pop()); if (stack.Top == null) continue; } } if (i.ToString() == "+" || i.ToString() == "/" || i.ToString() == "*" || i.ToString() == "-") { if (prevOperator) { throw new InvalidOperationException("Error"); } if (stack.Top != null) { if (GetPriority(i.ToString()) > GetPriority(stack.Top.Object)) { /*output.Add(i.ToString()); output.Add(stack.Pop());*/ stack.Push(i.ToString()); } else { stack.Push(i.ToString()); } } else { stack.Push(i.ToString()); } prevOperator = true; } } if (counter == input.Length - 1) { while (stack.Top != null) { if (stack.Top.Object == "(" || stack.Top.Object == ")") { stack.Pop(); } else { output.Add(stack.Pop()); } } } counter++; } return output.ToArray(); }