Java 实例 – 利用堆栈将中缀表达式转换成后缀表达式

Java 实例

以下实例演示了如何使用堆栈进行表达式的堆栈将中缀(Infix)表达式转换成后缀(postfix)表达式:

import java.io.IOException;
 
public class InToPost {
   private Stack theStack;
   private String input;
   private String output = "";
   public InToPost(String in) {
      input = in;
      int stackSize = input.length();
      theStack = new Stack(stackSize);
   }
   public String doTrans() {
      for (int j = 0; j

以上代码运行输出结果为:

124*5/+7-36/+
Postfix is 124*5/+7-36/+

Java 实例