Heim > Backend-Entwicklung > PHP-Tutorial > PHP实现的字典序排列算法_PHP教程

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Freigeben: 2016-07-13 16:58:19
Original
995 Leute haben es durchsucht

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] $j--;
$t = $c[$i-1];
$c[$i-1] = $c[$j];
$c[$j] = $t;
//echo $i."-".$j."
";
for ($j=$s-1; $i {
$t = $c[$i];
$c[$i] = $c[$j];
$c[$j] = $t;
}
return true;
}
$i--;
}
for ($i = 0, $j=$s-1; $i {
$t = $c[$i];
$c[$i] = $c[$j];
$c[$j] = $t;
}
return false;
}
?>


排列-字典法








当前元素: echo $data; ?>








$num ;
}
while (nextpermu ($a));
?>
序号 排列
echo $num; ?> echo implode (" ", $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...
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Aktuelle Ausgaben
PHP-Datenerfassung?
Aus 1970-01-01 08:00:00
0
0
0
PHP-Erweiterung intl
Aus 1970-01-01 08:00:00
0
0
0
Wie man PHP gut lernt
Aus 1970-01-01 08:00:00
0
0
0
Mehrere PHP-Versionen
Aus 1970-01-01 08:00:00
0
0
0
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage