常用PHP算法

1、冒泡排序

冒泡排序,

/**
	 * @title  冒泡排序
	 * @author lyj [author] [2018-07-11]
	 * @param  [type] $arr [description]
	 * @return [type]      [description]
	 */
	function bubble_sort($arr) 
	{
		$n = count($arr);
		for ($i = 0; $i < $n - 1; $i++) {
			for ($j = $i + 1; $j < $n; $j++) {
				if ($arr[$j] < $arr[$i]) {
					$temp = $arr[$i];
					$arr[$i] = $arr[$j];
					$arr[$j] = $temp;
				}
			}
		}
		return $arr;
	}
posted @ 2018-07-11 11:26  tang1jun  阅读(75)  评论(0编辑  收藏  举报