Home > php教程 > php手册 > php 插入排序

php 插入排序

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 10:52:12
Original
1394 people have browsed it

[php]
 //插入排序  按从小到大排序 
 $insert=array(); 
 for($i=0;$i  { 
     $insert[$i]=rand(0,30000); 
 } 
 //print_r($insert); 
 function insertsort(&$arr) 
 { 
   //插入排序把第一个当做是有序的  所以 i从1开始 
   for($i=1;$i        { 
         $insertval=$arr[$i]; 
         $insertindex=$i-1; 
         //寻找插入点 
         while($insertindex>=0&&$insertval              { //往后移数字 
               $arr[$insertindex+1]=$arr[$insertindex]; 
               $insertindex--; 
             } 
             //插入值 
             $arr[$insertindex+1]=$insertval; 
       } 
 } 
 insertsort($insert); 
 print_r($insert); 
?> 


 

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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template