Skip to content

Commit

Permalink
测试快排
Browse files Browse the repository at this point in the history
  • Loading branch information
yaowen369 committed Feb 16, 2017
1 parent 11e3ca7 commit 5f3501d
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
5 changes: 3 additions & 2 deletions 2016_spring/task2_19/src/task_19.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var queue = {
},

maxPrompt:function(){
alert("已经达到了我们的上限制" + this.maxQuantity + "个,不能再添加了")
alert("已经达到了我们的上限制" + this.maxQuantity + "个,不能再添加了") ;
},

emptyPrompt:function(){
Expand All @@ -86,7 +86,8 @@ var queue = {
debugPrint:function(){
console.log(this.arr);
}
};

}; //end of "var queue = {... "


function leftInsertClick(){
Expand Down
Empty file.
51 changes: 51 additions & 0 deletions 2016_spring/test/test0216/task_0216.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@


const N = 5;
var arr = [];


function creaetArrClick(){
for (let i=0; i<N; i++){
arr[i] = Math.ceil(Math.random()*100);
}
debugPrint("生成字符串");
}

function quickSortClick(){
quickSort(arr, 0, arr.length-1);
debugPrint("排序之后");
console.log("---------------------------");
}

function quickSort(dataArr, low1, high1){
var pivotpos = -1;
while(low1 < high1){
pivotPos = oneQuickSort(dataArr, low1, high1);
quickSort(dataArr, low1, pivotPos-1);
quickSort(dataArr, pivotPos+1, high1);
}
}

//一趟快排
function oneQuickSort(dataArr, low2, high2){
// dataArr[0] = dataArr[low];
var piovtKey = dataArr[low2];
while(low2 < high2){
while(low2<high2 && dataArr[high2]>=piovtKey){
high2--;
}
dataArr[low2] = dataArr[high2];
while(low2<high2 && dataArr[low2]<=piovtKey){
low2++;
}
dataArr[high2] = dataArr[low2];
}
dataArr[low2] = piovtKey;
return low2;
}

function debugPrint(str){
console.log( str + " " + arr);
}


15 changes: 15 additions & 0 deletions 2016_spring/test/test0216/test_0216.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>test 0216</title>
<link href="style_0216.css" type="text/css" rel="stylesheet"/>
<script src="task_0216.js"></script>
</head>
<body>
<p>测试而已</p>
<input type="button" value="生成长度为10数组" onclick="creaetArrClick()"/>
<input type="button" value="快速排序" onclick="quickSortClick()"/>
<input type="button" value="debugPrint" onclick="debugPrint()"/>
</body>
</html>

0 comments on commit 5f3501d

Please sign in to comment.