/*在栈中加入如下方法*/
/*----------------栈的表达式结果--------*/
/*
* 判断是否是运算符*/
public boolean isOper(char c){
return c=='+'||c=='-'||c=='*'||c=='/';
}
/*判断运算符优先级,使用数字来表示,数字越大优先级越大*/
public int priority(int oper){
if(oper=='*'||oper=='/'){
return 1;
}else if (oper=='+'||oper=='-'){
return 0;
}else{
return -1;
}
}
/*获取当前栈的大小*/
public int stackLenth(){
return this.stack.length;
}
/*查看栈顶的数据*/
public int peek(){
return this.stack[top];
}
/*计算的方法
* 2+3
* 3=num1 , 2 = num2*/
public int calculate(int num1,int num2,int oper){
int result = 0;
switch (oper){
case '+':
result = num2 +
(JAVA)使用栈完成String字符串表达式计算
最新推荐文章于 2023-08-07 11:05:43 发布