import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
public class Polan {
public static void main(String[] args) {
//先定义波兰表达式
//(3+2)*5-4 =》 3 2 + 5 * 4 —
String Expression="3 2 + 5 * 4 —";
//将后缀表达式放在ArrayList中
List<String> list =getList(Expression);
System.out.println("list="+list);
int res= Integer.parseInt(calculate(list));
System.out.println("计算的结果是="+res);
}
//将波兰表达式,依次将数据和运算符放入到ArrayList中
public static List<String> getList(String Exxpression){
//分割
String[] split =Exxpression.split(" ");
List<String> list=new ArrayList<>();
for (String ele:split){
list.add(ele);
}
return list;
}
public static String calculate(List<String> ls) {
//创建栈
Stack<String> stack = new Stack<String>()
标签:String,list,代码,List,波兰,ArrayList,public,表达式
From: https://blog.csdn.net/2303_78143972/article/details/137196191