PHP 写法:
function sortCustom($arr):array { for($i = 0; $i< count($arr); $i ++){ for ($j = 0;$j < count($arr) - $i -1; $j ++){ if($arr[$j] > $arr[$j + 1]){ $temp = $arr[$j]; $arr[$j] = $arr[$j + 1]; $arr[$j+1] = $temp; } } } return $arr; }
python写法
list1 = [-2, 3, 42, 1, 4, 6] def sort(list1) -> list: length = len(list1) for i in range(0, length - 1): for j in range(0, length - i - 1): if list1[j] > list1[j + 1]: list1[j], list1[j + 1] = list1[j + 1], list1[j] return list1 print(sort(list1))
标签:arr,--,list1,冒泡排序,python,length,PHP From: https://www.cnblogs.com/wujf-myblog/p/17137494.html