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

PHP 实现的字典序排列算法

WBOY
Release: 2016-06-08 17:33:24
Original
1297 people have browsed it
<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>  
Copy after login








当前元素: echo $data; ?>







$num = 1;
do
{
?>




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



Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template