冒泡排序

 

<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title></title>
</head>
<body>
	<script>
	// 冒泡排序
	var arr = [1,4,6,9,10,8,100,88];
	var ln =arr.length;
	var t=0
	for(var i=0;i<ln;i++){
		for(var m=i+1; m<ln; m++){
			t++
			// console.log(arr[i],arr[m])
			if(arr[i]>arr[m]){
				var tmp=arr[m];
				arr[m] = arr[i];
				arr[i] = tmp;
			}
		}
	}
	console.log(arr,t,ln)
	</script>
</body>
</html>

 

posted @ 2018-03-27 18:47  幽竹小妖  阅读(93)  评论(0编辑  收藏  举报