Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit46bc844

Browse files
committed
Add several more comments to in place quick sort.
1 parent66f19d6 commit46bc844

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

‎src/algorithms/sorting/quick-sort/QuickSortInPlace.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ export default class QuickSortInPlace extends Sort {
66
* This process is difficult to describe, but much clearer with a visualization:
77
*@see: http://www.algomation.com/algorithm/quick-sort-visualization
88
*
9-
*@param {*[]} originalArray
9+
*@param {*[]} originalArray - Not sorted array.
1010
*@param {number} inputLowIndex
1111
*@param {number} inputHighIndex
12-
*@return {*[]}
12+
*@param {boolean} recursiveCall
13+
*@return {*[]} - Sorted array.
1314
*/
1415
sort(
1516
originalArray,
@@ -21,18 +22,19 @@ export default class QuickSortInPlace extends Sort {
2122
constarray=recursiveCall ?originalArray :[...originalArray];
2223

2324
/**
24-
*`partition` operates on the subarray between lowIndex and highIndex, inclusive.
25-
*it arbitrarily chooses the last element in the subarray as the pivot.
26-
*then, it partially sorts the subarray into elements than are less than the pivot,
25+
*The partitionArray() operates on the subarray between lowIndex and highIndex, inclusive.
26+
*It arbitrarily chooses the last element in the subarray as the pivot.
27+
*Then, it partially sorts the subarray into elements than are less than the pivot,
2728
* and elements that are greater than or equal to the pivot.
28-
*each time`partition` is executed, the pivot element is in its final sorted position.
29+
*Each timepartitionArray() is executed, the pivot element is in its final sorted position.
2930
*
3031
*@param {number} lowIndex
3132
*@param {number} highIndex
3233
*@return {number}
3334
*/
34-
constpartition=(lowIndex,highIndex)=>{
35+
constpartitionArray=(lowIndex,highIndex)=>{
3536
/**
37+
* Swaps two elements in array.
3638
*@param {number} leftIndex
3739
*@param {number} rightIndex
3840
*/
@@ -43,7 +45,7 @@ export default class QuickSortInPlace extends Sort {
4345
};
4446

4547
constpivot=array[highIndex];
46-
// visitingCallback is used for time-complexity analysis
48+
// visitingCallback is used for time-complexity analysis.
4749
this.callbacks.visitingCallback(array[pivot]);
4850

4951
letpartitionIndex=lowIndex;
@@ -63,9 +65,9 @@ export default class QuickSortInPlace extends Sort {
6365
returnpartitionIndex;
6466
};
6567

66-
// Base case is when low and high converge
68+
// Base case is when low and high converge.
6769
if(inputLowIndex<inputHighIndex){
68-
constpartitionIndex=partition(inputLowIndex,inputHighIndex);
70+
constpartitionIndex=partitionArray(inputLowIndex,inputHighIndex);
6971
constRECURSIVE_CALL=true;
7072
this.sort(array,inputLowIndex,partitionIndex-1,RECURSIVE_CALL);
7173
this.sort(array,partitionIndex+1,inputHighIndex,RECURSIVE_CALL);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp