Home > Backend Development > PHP Tutorial > php 抉择排序

php 抉择排序

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 10:45:46
Original
962 people have browsed it

php 选择排序

<?php //选择排序 //从小到大排序  //date_default_timezone_set('Aisa/Shanghai');  $select=array(); for($i=0;$i<500;$i++) { 	 $select[$i]=rand(0,3000); }function selectsort(&$arr){     $temp=0;  for($i=0;$i<count($arr)-1;$i++)	{      $minval=$arr[$i];  //每一次认为第i个数是最小值	  $minindex=$i;	  for($j=$i+1;$j<count($arr);$j++)		  {		  //说明目前的值并不是最小值		  if($minval>$arr[$j])			  {			   $minval=$arr[$j];			   $minindex=$j;			  }		  }		  //内层for循环结束后再进行交换  这正是选择排序叫冒泡排序优越的地方		  $temp=$arr[$i];		  $arr[$i]=$arr[$minindex];          $arr[$minindex]=$temp;	} }	selectsort($select);	print_r($select);	//date_default_timezone_set('Aisa/Shanghai');?>
Copy after login
//www.17xuexiba.com
Copy after login

Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template