目录
方法名:pareseSuffixExpreesionList
项目思路:
1.将数学式子变为list为后面的做准备
2.将中缀的list按照要求转换为后缀表达式
项目的gitee地址
项目代码:
方法名:toInFixExpressionList
注解:将转为list形式的中缀表达式
/**
* create by: ALi
* description: 将字符串"1+((2+3)*4)-5"变为list:[1, +, (, (, 2, +, 3, ), *, 4, ), -, 5]
* create time: 2021/11/6 14:01
* @Param: string:"1+((2+3)*4)-5"
* @return [1, +, (, (, 2, +, 3, ), *, 4, ), -, 5]
*/
public static List<String> toInFixExpressionList(String string){
List<String> list = new ArrayList<String>();
char c;
String str ="";//拼接数字
for (int i = 0;i<string.length();){
c = string.charAt(i);
if(c < 48 || c > 57){//c非数字
list.add("" + c);
i++;
}else {
str = "";
//拼接数字
while (i<string.length() && (c=string.charAt(i)) >= 48 && (c=string.charAt(i)) <= 57){
str = str + c;
i++;
}
list.add(str);
}
}
return list;
}
方法名:pareseSuffixExpreesionList
注解:由中缀表达式=>后缀表达式:
/**
* create by: ALi
* description: 由中缀表达式=>后缀表达式
* create time: 2021/11/6 14:30
*
* @Param: list:[1, +, (, (, 2, +, 3, ), *, 4, ), -, 5]
* @return [1, 2, 3, +, 4, *, +, 5, -]
*/
public static List<String> pa