php实现插入排序,php实现排序<?php/** * 插入排序 * @param array $a 无序集合 * @return array 有序集合 */function insertsort($a) {  $temp;  $i;  $j;  $size_a = count($a);  # 从第二个元素开始  for ($i = 1; $i < $size_a; $i++) {          if ($a[$i] 0 && $temp<$a[$j-1]) {        $a[$j] = $a[$j-1];        $j--;      }             # 插入元素      $a[$j] = $temp;    }  }  return $a;}/** * 获取随机数 * @param integer $size 数量 * @return integer */function randomnumber($size = 10) {  $rand = array();  srand(time(null));  for ($i = 0; $i < $size; $i++) {    array_push($rand, mt_rand(0,1000));     }  return $rand;} $a = randomnumber();echo sprintf(unsorted list %s\n, implode( , $a));echo sprintf(sorted list %s\n, implode( , insertsort($a)));
以上就是本文所述的全部内容了,希望大家能够喜欢。
http://www.bkjia.com/phpjc/975525.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/975525.htmltecharticlephp实现插入排序,php实现排序 php/** * 插入排序 * @param array $a 无序集合 * @return array 有序集合 */function insertsort($a) { $temp; $i; $j; $size_a = count...
   
 
   