首页  >  文章  >  后端开发  >  php冒泡法排序代码

php冒泡法排序代码

WBOY
WBOY原创
2016-07-25 08:43:20866浏览
  1. function bubbleSort ($items) {
  2. $size = count($items);
  3. for ($i=0; $i for ($j=0; $j if ($items[$j+1] arraySwap($items, $j, $j+1);
  4. }
  5. }
  6. }
  7. return $items;
  8. }
  9. function arraySwap (&$arr, $index1, $index2) {
  10. list($arr[$index1], $arr[$index2]) = array($arr[$index2], $arr[$index1]);
  11. }
复制代码

php


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn