php木桶排序

<?php
	//木桶排序
	$count = array(6,10,4,12,4,90,33);

	function mutong($max,$array)
	{
		//填充木桶
		$arr = array_fill(0, $max, 0);
		//開始標示木桶
		for($i = 0; $i<=count($array)-1 ; $i++){
			//var_dump($array[$i]);

			$arr[$array[$i]]++;
		}
		$mutomg = array();
		//開始從木桶中拿出數據
		for($i = 0; $i<= $max ; $i++){
			for($j = 1; $j <= $arr[$i]; $j++){ //這一行主要用來控制輸出多個數字
				$mutong[] = $i;
			}
		}
		return $mutong;
	}

	var_dump(mutong(90,$count));
相關文章
相關標籤/搜索