/// <summary> /// Calculator /// </summary> /// <param name="reader"></param> /// <param name="writer"></param> public static void Calculator(TextReader reader, TextWriter writer) { //TODO: more info here int i1; IStack stack = new StackAsLinkedList(); while ((i1 = reader.Read()) > 0) { char ch = (char)i1; if (Char.IsDigit(ch)) { stack.Push((ch - '0')); } else if (ch == '+') { int j1 = (int)stack.Pop(); int k1 = (int)stack.Pop(); stack.Push((k1 + j1)); } else if (ch == '*') { int i2 = (int)stack.Pop(); int j2 = (int)stack.Pop(); stack.Push((j2 * i2)); } else if (ch == '=') { int k2 = (int)stack.Pop(); writer.WriteLine(k2); } } }
/// <summary> /// Constructor, internal /// </summary> /// <param name="stack"></param> internal Enumerator(StackAsLinkedList stack) { position = null; this.stack = stack; }