Skip to content

Commit

Permalink
1.修复括号不匹配。2.除法也要优先于乘法运算
Browse files Browse the repository at this point in the history
  • Loading branch information
SeasClouds committed Oct 15, 2018
1 parent 80550d6 commit 996974b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions php/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.idea
vendor
*my*
Queue
10 changes: 10 additions & 0 deletions php/Stack/Compute.php → php/08_stack/Compute.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -70,6 +77,9 @@ function compute(&$numStack, &$operStack){
case '-':
array_push($numStack, array_pop($numStack) - $num);
break;
case '(':
throw new \Exception("不匹配的(", 2);
break;

}
}
Expand Down

0 comments on commit 996974b

Please sign in to comment.