Home >Backend Development >PHP Tutorial >PHP 实现的字典序排列算法_PHP

PHP 实现的字典序排列算法_PHP

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-01 12:32:031265browse

感谢 bird 告诉我 $_POST[] 的用法。代码如下:

<?php <BR>  if ($_POST["perdata"] == "")<br>  {<br>    $_POST["perdata"] = "1 2 3 4";<br>  }<br><br>  $data = chop (trim ($_POST["perdata"]));<br>  $a = explode (" ", $data);<br>  sort ($a);<br>  $data = implode (" ", $a);<br>?><br><br><?php <BR>function nextpermu (&$c)<br>{<br>  $s = sizeof ($c);<br>  $i = $s - 1;<br><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><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