< ?php header('Content-Type: text/html; charset=UTF-8'); class quanpailie { var $startTime = 0; var $stopTime = 0; function get_microtime() { list($usec, $sec) = explode(' ', microtime()); return ((float)$usec + (float)$sec); } function start() { $this->startTime = $this->get_microtime(); } function stop() { $this->stopTime = $this->get_microtime(); } function spent() { return round(($this->stopTime - $this->startTime) * 1000, 3); } function type($list, $k, $m) { if($k==$m) { for($i=0; $i< =$m; $i++) { echo $list[$i]; } echo "\n"; } else { for($i=$k; $i<=$m; $i++) { $this->swap($list[$k], $list[$i]); $this->type($list, $k+1, $m); $this->swap($list[$k], $list[$i]); } } } public function swap(&$a, &$b) { $temp=$a; $a=$b; $b=$temp; } } $aa=new quanpailie(); $aa->start(); $str = 'abcde'; $aa->type(str_split($str), 0, 2); $aa->stop(); echo "<br />页面执行时间: ". $aa->spent() . " 毫秒"; ?>
php 实现全排列
[ 2010年04月20日 19:00 | by Veidy.lei ] 2 评论 » | 阅读次数:11,375
本文引用地址:
上一篇:
下一篇:windows 7
这样的代码风格我喜欢
[回复]
就是这个类名 “quanpailie”。。。。看着蛋疼。。
[回复]