一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

PHP实现的字典序排列算法

时间:2008-03-13 编辑:简简单单 来源:一聚教程网

if ($_POST["perdata"] == "")
{
$_POST["perdata"] = "1 2 3 4";
}
$data = chop (trim ($_POST["perdata"]));
$a = explode (" ", $data);
sort ($a);
$data = implode (" ", $a);
?>
function 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."
";
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;
}
?>


排列-字典法









当前元素:








$num ;
}
while (nextpermu ($a));
?>
序号 排列


热门栏目