Home > Backend Development > PHP Tutorial > PHP insertion sort implementation code_PHP tutorial

PHP insertion sort implementation code_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 15:12:33
Original
693 people have browsed it

Algorithm description:

⒈ Starting from the first element, this element can be considered to have been sorted
⒉ Take out the next element and scan from back to front in the sorted element sequence
⒊ If the element (sorted) is greater than the new element, move the element to the next position
⒋ Repeat step 3 until you find the position where the sorted element is less than or equal to the new element
⒌ Insert the new element into the next position
⒍ Repeat step 2

Copy code The code is as follows:

$arr =array(123,0,5,-1,4,15);

function insertSort(&$arr){

                                                                                                                                                                                                                                               Insert the compared number
             $insertVal=$arr[$i]; 
                                              through Find location
while($insertIndex>=0 && $insertVal<$arr[$insertIndex]){

                                                                                                                                                          🎜>
                                                                                                                                                                                                                            ;
insertSort($arr);
print_r($arr);

?>





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

www.bkjia.com

true

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

TechArticleAlgorithm description: ⒈ Starting from the first element, the element can be considered to have been sorted ⒉ Take out the next element, Scan from back to front in the sorted sequence of elements ⒊ If the element...

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