Home >php教程 >PHP源码 >PHP 实现的字典序排列算法

PHP 实现的字典序排列算法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-08 17:33:241334browse
<script>ec(2);</script>
感谢 bird 告诉我 $_POST[] 的用法。代码如下:
<?php <br />  if ($_POST["perdata"] == "")<br>  {<br>    $_POST["perdata"] = "1 2 3 4";<br>  }<br>  $data = chop (trim ($_POST["perdata"]));<br>  $a = explode (" ", $data);<br>  sort ($a);<br>  $data = implode (" ", $a);<br>?><br><?php <br />function nextpermu (&$c)<br>{<br>  $s = sizeof ($c);<br>  $i = $s - 1;<br>  while ($i > 0)<br>  {<br>    if ($c[$i] > $c[$i-1])<br>    {<br>      $j = $s-1;<br>      while ($c[$j]         $j--;<br>      $t = $c[$i-1];<br>      $c[$i-1] = $c[$j];<br>      $c[$j] = $t;<br>      //echo $i."-".$j."<br>";<br>      for ($j=$s-1; $i       {<br>        $t = $c[$i];<br>	$c[$i] = $c[$j];<br>	$c[$j] = $t;<br>      }<br>      return true;<br>    }<br>    $i--;<br>  }<br>  for ($i = 0, $j=$s-1; $i   {<br>    $t = $c[$i];<br>    $c[$i] = $c[$j];<br>    $c[$j] = $t;<br>  }<br>  return false;<br>}<br>?><br><br><br>  <title>排列-字典法</title><br><br><br>  








当前元素: echo $data; ?>







$num = 1;
do
{
?>




$num ;
}
while (nextpermu ($a));
?>
序号 排列
echo $num; ?> echo implode (" ", $a); ?>



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:BMForumNext article:如何在自己的主页上使用PHP