澳门新葡萄京官网注册PHP 实现的字典序排列算法

澳门新葡萄京官网注册,感谢 bird 告诉我 $_POST[] 的用法。代码如下:

?php if ($_POST["perdata"] == "") { $_POST["perdata"] = "1 2 3 4"; } $data = chop (trim ($_POST["perdata"])); $a = explode (" ", $data); sort ($a); $data = implode (" ", $a);??phpfunction nextpermu ($c){ $s = sizeof ($c); $i = $s - 1; while ($i  0) { if ($c[$i]  $c[$i-1]) { $j = $s-1; while ($c[$j] = $c[$i-1]) $j--; $t = $c[$i-1]; $c[$i-1] = $c[$j]; $c[$j] = $t; //echo $i."-".$j."br"; for ($j=$s-1; $i  $j; $i , $j--) { $t = $c[$i];$c[$i] = $c[$j];$c[$j] = $t; } return true; } $i--; } for ($i = 0, $j=$s-1; $i  $j; $i , $j--) { $t = $c[$i]; $c[$i] = $c[$j]; $c[$j] = $t; } return false;}?htmlhead title排列-字典法/title/headbody form action="permutation.php" method="post" table tr tdinput type="text" name="perdata"/td tdinput type="submit" value="排列"/td /tr /table /form p当前元素:? echo $data; ?/p table width="60%" tr th width="50" bgcolor="yellow"序号/th th bgcolor="EEEEFF"排列/th /tr?php $num = 1; do {? tr td align="center"? echo $num; ? /td td? echo implode (" ", $a); ?/td /tr?php $num ; } while (nextpermu ($a));? /table/body/html

发表评论

电子邮件地址不会被公开。 必填项已用*标注