Last active
February 1, 2020 16:00
-
-
Save anjanesh/14d04cc302a7c57a3a0151ad9a098eeb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$s = "((a+b*d)*(x/2))*(1+(y+(x-2)/10))"; | |
$b = []; | |
$j = 0; | |
$stack = []; | |
for ($i = 0; $i < strlen($s); $i++) | |
{ | |
if ($s[$i] == '(') | |
{ | |
$b[++$j] = ''; | |
} | |
elseif ($s[$i] == ')') | |
{ | |
$stack[] = ($b[$j--] .= ')'); | |
} | |
for ($k = 1; $k <= $j; $k++) | |
{ | |
$b[$k] .= $s[$i]; | |
} | |
} | |
echo $s.PHP_EOL; | |
print_r($stack); | |
echo PHP_EOL; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment