PHP Data Structure 6: Application example of PHP stack-number conversion and matching algorithm of brackets
GetPushStack ($ mod); $ a = (int) ($ a-$ mod)/$ output_scale;} $ elems = $ stack-> getAllPopStack (); $ output = ''; if ($ output_scale = 16) {$ output. = '0x ';} elseif ($ output_scale = 8) {$ output. = '0';} foreach ($ elems as $ value) {if ($ output_scale = 16) {switch ($ value) {case 10: $ value = 'a '; break; case 11: $ value = 'B'; break; case 12: $ value = 'C'; break; case 13: $ value = 'd'; break; case 14: $ value = 'e'; break; case 15: $ value = 'F'; break;} $ output. = $ Value;} // because the output statement automatically converts the number of integers into a 10-digit output // if the converted result is 0xff, directly output 0xff will get 255, so return an array return array ('before' => $ input, 'after' => intval ($ output, $ output_scale ), 'stringclass' => $ output);} else {return 0 ;}} else {return 0 ;}} /*** implement the bracket matching algorithm ** @ param string $ str * @ return mixed match success returns an array; otherwise, false */function bracketmatch ($ str) is returned) {$ substr = ''; $ brackets = array (); $ stack = new StackLinked (); $ strlen = strlen ($ str); $ leftb = "("; $ rightb = ")"; For ($ I = 0; $ I <$ strlen; $ I ++) {$ cu = $ str [$ I]; if (ord ($ cu)> 127) {$ cu = substr ($ str, $ I, 2); $ I ++;} if ($ cu = $ leftb) {if (strlen ($ substr)> 0) {$ e = array ('V' => $ substr, 'd => 'L'); $ stack-> getPushStack ($ e );} $ stack-> getPushStack ($ cu); $ substr = '';} if ($ cu = $ rightb) {if (strlen ($ substr)> 0) {$ e = array ('V' = >$ substr, 'D '=> 'r'); $ stack-> getPushStack ($ e ); $ substr = '';} $ bl = '('; $ tag = true; $ remain = $ stack-> getCountForElem ('); $ e1 = ''; while ($ t Ag &&! $ Stack-> getIsEmpty () {$ stack-> getPopStack ($ e1); if ($ e1 ==$ leftb) {$ bl. = ')'; $ brackets [$ remain] [] = $ bl; $ tag = false;} else {if ($ e1 ['D'] = 'l ') {$ bl = '('. $ e1 ['V']. substr ($ bl, 1);} else {$ bl. = $ e1 ['V'] ;}}} if ($ cu! = '(' & $ Cu! = ') {$ Substr. = $ cu ;}} if ($ stack-> getCountForElem (') = 0) {$ stack-> getAllPopStack (); return $ brackets ;} else {return false ;}}$ num = 255; $ output_scale = 16; $ renum = scaleconvert ($ num, $ output_scale ); echo "10 hexadecimal number {$ renum ['before']} to {$ output_scale} hexadecimal :". $ renum ['stringclass']; echo"
"; Var_dump (bracketmatch (" (sfsf (Xu dianyang () sfsdf) (sfsf) sdfsa (La) stay abc) "); echo"
";?>