@@ -6,10 +6,11 @@ export default class QuickSortInPlace extends Sort {
6
6
* This process is difficult to describe, but much clearer with a visualization:
7
7
* @see : http://www.algomation.com/algorithm/quick-sort-visualization
8
8
*
9
- * @param {*[] } originalArray
9
+ * @param {*[] } originalArray - Not sorted array.
10
10
* @param {number } inputLowIndex
11
11
* @param {number } inputHighIndex
12
- * @return {*[] }
12
+ * @param {boolean } recursiveCall
13
+ * @return {*[] } - Sorted array.
13
14
*/
14
15
sort (
15
16
originalArray ,
@@ -21,18 +22,19 @@ export default class QuickSortInPlace extends Sort {
21
22
const array = recursiveCall ? originalArray : [ ...originalArray ] ;
22
23
23
24
/**
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,
27
28
* 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 time partitionArray() is executed, the pivot element is in its final sorted position.
29
30
*
30
31
* @param {number } lowIndex
31
32
* @param {number } highIndex
32
33
* @return {number }
33
34
*/
34
- const partition = ( lowIndex , highIndex ) => {
35
+ const partitionArray = ( lowIndex , highIndex ) => {
35
36
/**
37
+ * Swaps two elements in array.
36
38
* @param {number } leftIndex
37
39
* @param {number } rightIndex
38
40
*/
@@ -43,7 +45,7 @@ export default class QuickSortInPlace extends Sort {
43
45
} ;
44
46
45
47
const pivot = array [ highIndex ] ;
46
- // visitingCallback is used for time-complexity analysis
48
+ // visitingCallback is used for time-complexity analysis.
47
49
this . callbacks . visitingCallback ( array [ pivot ] ) ;
48
50
49
51
let partitionIndex = lowIndex ;
@@ -63,9 +65,9 @@ export default class QuickSortInPlace extends Sort {
63
65
return partitionIndex ;
64
66
} ;
65
67
66
- // Base case is when low and high converge
68
+ // Base case is when low and high converge.
67
69
if ( inputLowIndex < inputHighIndex ) {
68
- const partitionIndex = partition ( inputLowIndex , inputHighIndex ) ;
70
+ const partitionIndex = partitionArray ( inputLowIndex , inputHighIndex ) ;
69
71
const RECURSIVE_CALL = true ;
70
72
this . sort ( array , inputLowIndex , partitionIndex - 1 , RECURSIVE_CALL ) ;
71
73
this . sort ( array , partitionIndex + 1 , inputHighIndex , RECURSIVE_CALL ) ;
0 commit comments