-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
69 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |