search
Homephp教程php手册php选择排序

php选择排序

Jun 13, 2016 am 10:52 AM
datedefaultphpsetsortchoose

[php]
 //选择排序 
 //从小到大排序 
  
  
//date_default_timezone_set('Aisa/Shanghai');  
 $select=array(); 
 for($i=0;$i  {  
     $select[$i]=rand(0,3000); 
 } 
function selectsort(&$arr) 
{    
  $temp=0; 
  for($i=0;$i     { 
      $minval=$arr[$i];  //每一次认为第i个数是最小值 
      $minindex=$i; 
      for($j=$i+1;$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'); 
?> 
[php]

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.