+ +$i){ for($j=$len; $j>$i; --$j) {- if($array[$j] < $array[$j-1])
- {
- $temp = $array[$j];
- $array[$j] = $array[$j-1];
- $array[$j-1] = $temp;
- }
- }
- }
- return $ array;
- }
print ' ';</li>
<li>print_r(bubbingSort(array(1,4,22,5,7,6,9)));</li>
<li>print '< ;/pre>';</li>
<li>?></p></li>
<li>
<li>
<li>
<li>Copy code</li>
<li>
<li>
<li>
<li>
<li>implementation principle of quick sort
</li>
<li>
</ol>First make sure that the first half of the list is smaller than the second half, and then sort the first half and the second half respectively, so that the entire list is in order.
</div>
<em onclick="copycode($('code_L6B'));"></em>
</div>
<p><u><strong><p><?php</strong>function quickSort(array $array)</u>{</p>$len = count($array);<div class="blockcode">if($len <= 1)<div id="code_Ayu">{<ol>return $ array;<li>}</li>
<li>$key = $array[0];</li>
<li>$left = array();</li>
<li>$right = array();</li>
<li>for($i=1; $i<$len; ++$i)</li>
<li> {</li>
<li>if($array[$i] < $key)</li>
<li>{</li>
<li>$left[] = $array[$i];</li>
<li>}</li>
<li>else</li>
<li>{</li>
<li>$right[] = $array[$i];</li>
<li> }</li>
<li>}</li>
<li>$left = quickSort($left);</li>
<li>$right = quickSort($right);</li>
<li>return array_merge($left, array($key), $right);</li>
<li>}</p></li>
<li>< p>print '<pre class="brush:php;toolbar:false">';</li>
<li>print_r(quickSort(array(1,4,22,5,7,6,9)));</li>
<li>print ' ';
- ?>< /p>
-
-
-
- Copy code
-
-
-
-
-
-
|