Copy CodeThe code is as follows:
/**
* Simple selection sort easy to choose
*
* Principle: Select each number in the array at a time, write down the current position and assume that it is the minimum number of min=i from the next number in the current position, start scanning until the last number from this number, and record the minimum position min, if min is not equal to I at the end of the scan, the hypothesis error is indicated. Then the number of min and I positions is exchanged.
*/
function Sort_simple_selection ($list)
{
$len = count ($list);
if (empty ($len)) return $list;
for ($i = 0; $i < $len; $i + +)
{
$min = $i;
for ($j = $i + 1; $j < $len; $j + +)
{
if ($list [$j] > $list [$min])//from large to small
if ($list [$j] < $list [$min])//from small to large
{
$min = $j;
}
echo implode (', ', $list). " #pos = ". ($min + 1). " Min= ". $list [$min]."
";
}
if ($min! = $i)
{
$temp = $list [$i];
$list [$i] = $list [$min];
$list [$min] = $temp;
}
echo "-------------------------
";
}
}
$list = Array (4,3,2,1,5,7,3,7);
$list = Sort_simple_selection ($list);
http://www.bkjia.com/PHPjc/324189.html www.bkjia.com true http://www.bkjia.com/PHPjc/324189.html techarticle Copy the code code as follows: PHP/** * Simple selection sort Easy selection Sort * * Principle: Select each number in the array at a time, note the current position and assume it is starting at the current position ...