private void DoSingleEvaluationWithPresidence(char ops) { int position = operationList.IndexOf(ops); double num1 = numberList[position]; double num2 = numberList[position + 1]; double result = CalculatorUtility.Evaluate('/', num1, num2); //remove numbers in position numberList.RemoveAt(position); operationList.RemoveAt(position); //put results back in numberList[position] = result; }
private double DoEvaluation() { if (numberList.Count >= 2) { //the idea is to evaluate 2 numbers at a time double num1 = numberList[0]; double num2 = numberList[1]; char ops = operationList[0]; double results = CalculatorUtility.Evaluate(ops, num1, num2); //1st 2 numbers are evaluate. //now we remove the first item operationList.RemoveAt(0); numberList.RemoveAt(0); //now we put result into the first location numberList[0] = results; //And then we repeat again } if (numberList.Count == 0) { return(0); } if (numberList.Count == 1) { return(numberList[0]); } else { // we do a nested loop, to evaluate the next pair of numbers //return DoEvaluation(); return(DoEvaluation()); } }