可惜没有激活码
激活码哪里来的?
发到邮箱里来的。 我是两点多申请的,所以快点吧。
这个就是将表达式转化成逆波兰的实现代码,我从书上抄的 (JAVA版的).这个程序将例如(a+b)*c等等任意复杂的式子转化过来. ------> a b + c * public class InfixToPostfix { String ifx; String pfx;
public void convertToPostfix() { StackClass stack = new StackClass(100); int i; char stackOpr; CharElement temp;
i=0; pfx = "";
int len = ifx.length();
for(i = 0; i < len; i++) if(ifx.charAt(i) >= 'A' && ifx.charAt(i) <= 'Z') pfx = pfx + ifx.charAt(i); else { switch(ifx.charAt(i)) { case '(': stack.push(new CharElement(ifx.charAt(i))); break;
case ')': temp = (CharElement) stack.top(); stack.pop(); stackOpr = (char) temp.getChar();
while(stackOpr != '(') { pfx = pfx + stackOpr;
if(!stack.isEmptyStack()) { temp = (CharElement) stack.top(); stack.pop(); stackOpr = (char)temp.getChar(); } else break; } break; case ';': case ' ': break;
default: if(stack.isEmptyStack()) stack.push(new CharElement(ifx.charAt(i))); else { temp = (CharElement) stack.top(); stack.pop(); stackOpr = (char) temp.getChar();
while(precedence(stackOpr,ifx.charAt(i))) { pfx = pfx + stackOpr; if(!stack.isEmptyStack()) { temp = (CharElement)stack.top(); stack.pop(); stackOpr = (char) temp.getChar();
} else break; }
if(!precedence(stackOpr,ifx.charAt(i))) stack.push(new CharElement(stackOpr));
stack.push(new CharElement(ifx.charAt(i))); }
}//end switch }//end else
while(!stack.isEmptyStack()) { temp = (CharElement)stack.top(); stack.pop();
pfx += (char) temp.getChar();
}
}//end convertToPostfix
public boolean precedence(char opr1, char opr2) { int prec1 = 0, prec2 = 0;
if(opr1 == '*' || opr1 =='/') prec1 = 2; else if(opr1 == '+' || opr1 == '-') prec1 = 1; else if(opr1 =='(') prec1 = 0;
if(opr2 == '*' || opr2 == '/') prec2 = 2; else if(opr2 =='+' || opr2 == '-') prec2 = 1;
return(prec1 >= prec2); }//end precedence
public void getInfix(String data) { ifx = data; convertToPostfix(); }
public void showInfix() { System.out.println("Infix: " + ifx); }
public void showPostfix() { System.out.println("Postfix: " + pfx); }
public InfixToPostfix(String infx) { ifx = infx; convertToPostfix(); } }