js 冒泡排序

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<script>
	window.onload = function (){
		var arr = [34,7,3,11,20];
		for(var i = 0; i < arr.length; i++){
			for(var j = 0; j < arr.length; j++){
				toCon();
			}
		}

		console.log(arr);

		function toCon(prev,next){
			var tmp = "";
			if(arr[prev] > arr[next]){
				tmp = arr[prev];
				arr[prev] = arr[next];
				arr[next] = tmp;
			}
		}
		return arr;
	}
	</script>
</head>
<body>
	
</body>
</html>

  

posted @ 2015-04-26 22:09  mayufo  阅读(422)  评论(0编辑  收藏  举报