1.修复括号不匹配。2.除法也要优先于乘法运算
This commit is contained in:
parent
80550d66de
commit
996974b4d2
2
php/.gitignore
vendored
2
php/.gitignore
vendored
@ -1,2 +1,4 @@
|
||||
.idea
|
||||
vendor
|
||||
*my*
|
||||
Queue
|
@ -28,6 +28,13 @@ function expression($str)
|
||||
array_push($operStack, $arr[$i]);
|
||||
break;
|
||||
case '*':
|
||||
$arrLen = count($operStack);
|
||||
while ($operStack[$arrLen-1] === '/'){
|
||||
compute($numStack, $operStack);
|
||||
$arrLen--;
|
||||
}
|
||||
array_push($operStack, $arr[$i]);
|
||||
break;
|
||||
case '/':
|
||||
case '(':
|
||||
array_push($operStack, $arr[$i]);
|
||||
@ -70,6 +77,9 @@ function compute(&$numStack, &$operStack){
|
||||
case '-':
|
||||
array_push($numStack, array_pop($numStack) - $num);
|
||||
break;
|
||||
case '(':
|
||||
throw new \Exception("不匹配的(", 2);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user