@@ -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 const array = 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 time partitionArray() 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- const partition = ( lowIndex , highIndex ) => {
35+ const partitionArray = ( 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 const pivot = 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 let partitionIndex = lowIndex ;
@@ -63,9 +65,9 @@ export default class QuickSortInPlace extends Sort {
6365 return partitionIndex ;
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- const partitionIndex = partition ( inputLowIndex , inputHighIndex ) ;
70+ const partitionIndex = partitionArray ( inputLowIndex , inputHighIndex ) ;
6971 const RECURSIVE_CALL = true ;
7072 this . sort ( array , inputLowIndex , partitionIndex - 1 , RECURSIVE_CALL ) ;
7173 this . sort ( array , partitionIndex + 1 , inputHighIndex , RECURSIVE_CALL ) ;
0 commit comments