首先声明,我是一个菜鸟。一下文章中出现技术误导情况盖不负责
<html>
<head>
<script type="text/javascript">
window.onload = function() {
var div = document.getElementById("cnt");
var arr = [3, 2, 5, 4, 7, 9, 11, 22, 14, 100, 45, 678, 232, 111, 45, 23, 11, 111];
quickSort(arr, 0, arr.length-1);
for(var i in arr) {
div.innerHTML = div.innerHTML + " " + arr[i];
}
}
function quickSort(arr, begin, end) {
if(end < begin) return;
var p = partition(arr, begin, end);
quickSort(arr, begin, p-1);
quickSort(arr, p+1, end);
}
function partition(arr, begin, end) {
var key = arr[begin];
var pivot = begin;
while(begin != end) {
while(arr[end] >= key && end != begin) {
end--;
}
while(arr[begin] <= key && begin != end) {
begin++;
}
if(begin != end) {
var tmp = arr[begin];
arr[begin] = arr[end];
arr[end] = tmp;
}
}
arr[pivot] = arr[begin];
arr[begin] = key;
return begin;
}
</script>
</head>
<body>
<div id="cnt"></div>
</body>
</html>
文章结束给大家分享下程序员的一些笑话语录: 联想——对内高价,补贴对外倾销的伟大“民族”企业。