Home  >  Article  >  Backend Development  >  Implementation of selection sort in PHP

Implementation of selection sort in PHP

小云云
小云云Original
2018-03-14 13:56:361222browse

This article mainly introduces to you the implementation of PHP selection sorting. The principle is: each traversal selects the smallest one on the right and exchanges its position with the one on the left. For example: in the first pass, select the first element 4 as a reference, find the right side of 4, and exchange the smallest number with 4 to become: 0, 1,8,4,6,7,2,9,3,200,0,656,5,12,12123,34,9,

$arr[$j]){			
$min= $j;		}	}	
if($min!=$i){	    $t = $arr[$i];		
$arr[$i] = $arr[$min];		$arr[$min] = $t;	
}		foreach($arr as $v){		
echo $v.",";	}		
echo "
"; } ?>

Related recommendations:

PHP simple selection sorting algorithm learning and sharing

Instance analysis of JavaScript implementation of selection sorting algorithm (picture)

php simple sorting bubble sort and selection sort

The above is the detailed content of Implementation of selection sort in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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