Home > Backend Development > PHP Tutorial > php insertion sort_PHP tutorial

php insertion sort_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 17:53:49
Original
997 people have browsed it

[php]
//Insertion sort Sort from small to large
$insert=array();
for($i=0;$i<200;$i++)
{
$insert[$i]=rand(0,30000);
}
//print_r($insert);
function insertsort(&$arr)
{
//Insertion sort treats the first one as ordered, so i starts from 1
for($i=1;$i                                                                              $insertval=$arr[$i];
           $insertindex=$i-1;
//Find the insertion point
​​​​​while($insertindex>=0&&$insertval<$arr[$insertindex])
{ //Move the number backward
                    $arr[$insertindex+1]=$arr[$insertindex];
$insertindex--;
                                                                                                                           //Insert value
                 $arr[$insertindex+1]=$insertval;
        } 
}
insertsort($insert);
print_r($insert);
?>


http://www.bkjia.com/PHPjc/477995.html

truehttp: //www.bkjia.com/PHPjc/477995.htmlTechArticle[php] ?php //Insertion sort is sorted from small to large $insert=array(); for($ i=0;$i200;$i++) { $insert[$i]=rand(0,30000); } //print_r($insert); function insertsort($arr) { //Insertion sort...
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
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template