private void Transfer(List <String> str) //中缀转化为后缀,存在sharedExp中 { Node currentNode; char ch, temp = '\0'; double op = 0; int length, n = 1; length = readInExp.Modify(str); chStack.Push('#', 0); while (true) { currentNode = readInExp.GetNode(n); ch = currentNode.ch; op = currentNode.op; if (ch == '\0') { sharedExp.LinkNode(ch, op); } else if (ch == ')') { for (chStack.Top(ref temp, ref op), chStack.Pop(); temp != '('; chStack.Top(ref temp, ref op), chStack.Pop()) { sharedExp.LinkNode(temp, 0); } }//end else if else { for (chStack.Top(ref temp, ref op), chStack.Pop(); Icp(ch) <= Isp(temp); chStack.Top(ref temp, ref op), chStack.Pop()) { sharedExp.LinkNode(temp, 0); } chStack.Push(temp, 0); chStack.Push(ch, 0); } if (n == length) { break; } n += 1; }//end while while (!chStack.IsEmpty()) { chStack.Top(ref temp, ref op); chStack.Pop(); if (temp != '#') { sharedExp.LinkNode(temp, 0); } } }//end method
public Pair Run(List <String> str) { Transfer(str); Node currentNode; char ch = '\0'; double op = 0.0; int length, n = 1; length = sharedExp.length; while (n <= length) { currentNode = sharedExp.GetNode(n); ch = currentNode.ch; op = currentNode.op; if (ch == '\0') { PushOperand(op); } else { if (DoOperator(ch)) { } else { answer.answer = 0; answer.flag = false; return(answer); } } n += 1; } if (opStack.Top(ref ch, ref op)) { answer.answer = op; answer.flag = true; return(answer); } answer.answer = 0; answer.flag = false; return(answer); }//end of method