⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 05c05-2.php

📁 介绍PHP5的给类型函数应用
💻 PHP
字号:
<?php// Implement the Insertion Sortfunction insertion_sort(&$a) {    // Loop through all entries in the array    $count = count($a);    for ($i = 0; $i < $count; $i++) {        // Save the current value which we are going to compare:        $value = $a[$i];                // Now loop backwards from the current value until we reach the        //  beginning of the array or a value less than our current one        for ($x = $i - 1; ( ($x >= 0) && ($a[$x] > $value) ); $x--) {            // Swap this value down one place:            $a[$x + 1] = $a[$x];        }                // Now assign our value to it's proper sorted position:        $a[$x + 1] = $value;    }}        // Prepare an array of values:$values = array(73, 3, 42, 6, 14, 23, 15, 9, 74, 1, 234, 45, 23, 76, 12, 3);// Sort them:insertion_sort($values);// Echo them out in order://  1 3 3 6 9 12 14 15 23 23 42 45 73 74 76 234foreach ($values as $v) { echo "{$v} "; }?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -