From 163ec3312bf3db41811113fd12ba82a916e440be Mon Sep 17 00:00:00 2001 From: icodeajk <1181674815@qq.com> Date: Thu, 7 Jun 2018 09:35:34 +0800 Subject: [PATCH 1/2] add some notes --- 6.quickSort.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/6.quickSort.md b/6.quickSort.md index 28ad477..eb8706f 100644 --- a/6.quickSort.md +++ b/6.quickSort.md @@ -51,7 +51,7 @@ function partition(arr, left ,right) { // 分区操作 if (arr[i] < arr[pivot]) { swap(arr, i, index); index++; - } + } } swap(arr, pivot, index - 1); return index-1; @@ -62,7 +62,10 @@ function swap(arr, i, j) { arr[i] = arr[j]; arr[j] = temp; } -function partition2(arr, low, high) { + + +/*方法二:记得有三个参数! + function partition2(arr, low, high) { let pivot = arr[low]; while (low < high) { while (low < high && arr[high] > pivot) { @@ -85,7 +88,7 @@ function quickSort2(arr, low, high) { quickSort2(arr, pivot + 1, high); } return arr; -} +} */ ``` From f283dc8d06ad5263b7411b1897f3a080677f242a Mon Sep 17 00:00:00 2001 From: icodeajk <1181674815@qq.com> Date: Thu, 7 Jun 2018 09:40:22 +0800 Subject: [PATCH 2/2] add some notes --- 5.mergeSort.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/5.mergeSort.md b/5.mergeSort.md index bf0de32..bd79090 100644 --- a/5.mergeSort.md +++ b/5.mergeSort.md @@ -41,7 +41,7 @@ ```js function mergeSort(arr) { // 采用自上而下的递归方法 var len = arr.length; - if(len < 2) { + if(len < 2) { //当分为一个元素时,所有最小子节点就是已经排好序的了! return arr; } var middle = Math.floor(len / 2), @@ -56,7 +56,7 @@ function merge(left, right) while (left.length && right.length) { if (left[0] <= right[0]) { - result.push(left.shift()); + result.push(left.shift()); //left.shift()返回left被删除的第一个元素! } else { result.push(right.shift()); } @@ -222,4 +222,4 @@ function merge($left, $right) return $result; } -``` \ No newline at end of file +```