Heim  >  Artikel  >  Backend-Entwicklung  >  冒泡排序与数组交集php做法_PHP教程

冒泡排序与数组交集php做法_PHP教程

WBOY
WBOYOriginal
2016-07-13 16:59:07817Durchsuche

冒泡排序-php教程版本-交换排序法

$a=array('11','2','13','4','22');
$num = count($a);
for($i=0;$i     for($j=0;$j         if($a[$i]             $temp = $a[$i];
            $a[$i]=$a[$j];
            $a[$j]=$temp;
        }
    }   
}
print_r($a);

归并排序-数组交集-php版

$a=array('1','2','3','4','22');
$b=array('1','3','4','11','22','23');
f($a, $b, 5, 6, $t);
print_r($t);
function f(&$a, &$b, $n, $m, &$t){
    $i=0;$j=0;
    while($i        
        if($a[$i]==$b[$j]){
            echo $a[$i]." ";//交集
            $t[]=$a[$i++];
            $t[]=$b[$j++];
        }elseif($a[$i]>$b[$j]){
             $t[]=$b[$j++];

        }else{
            $t[]=$a[$i++];

        }
       
    }
    while($i          $t[]=$a[$i++];
    }
   
     while($j          $t[]=$b[$j++];
    }
   
}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/631337.htmlTechArticle冒泡排序-php教程版本-交换排序法 $a=array('11','2','13','4','22'); $num = count($a); for($i=0;$i$num;$i++){ for($j=0;$j$num;$j++){ if($a[$i]$a[$j]){ $temp = $a[$i]; $a[...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn