Home > Backend Development > PHP Tutorial > Dictionary sorting algorithm implemented in PHP_PHP tutorial

Dictionary sorting algorithm implemented in PHP_PHP tutorial

WBOY
Release: 2016-07-13 16:58:19
Original
947 people have browsed it

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));
?>
序号 排列


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/631405.htmlTechArticle?php if ($_POST[perdata] == ) { $_POST[perdata] = 1 2 3 4; } $data = chop (trim ($_POST[perdata])); $a = explode ( , $data); sort ($a); $data = implode ( , $a); ? ?php function nex...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template