<script type="text/javascript">
var arr = [1, 2, 3, 54, 22, 1, 2, 3];
function quick(arr) {
if (arr.length <= 1)
return arr;
var proiindex = Math.floor(arr.length / 2);
var proift = arr.splice(proiindex, 1)[0]; //找基准,并把基准从原数组删除
var left = [];
var right = [];
for (var i = 0; i < arr.length; i++) {
if (arr[i] <= proift) {
left.push(arr[i]);
} else {
right.push(arr[i]);
}
}
return quick(left).concat([proift], quick(right));
}
document.write(quick(arr));
</script>
原文:http://www.cnblogs.com/xphdy/p/6057577.html