diff --git a/Algorithm/algorithm-ch.md b/Algorithm/algorithm-ch.md index 4aea4602..aba1dd1a 100644 --- a/Algorithm/algorithm-ch.md +++ b/Algorithm/algorithm-ch.md @@ -292,9 +292,9 @@ function sort(array) { function quickSort(array, left, right) { if (left < right) { - swap(array, , right) + swap(array, parseInt(Math.random() * (right - left + 1)) + left, right) // 随机取值,然后和末尾交换,这样做比固定取一个位置的复杂度略低 - let indexs = part(array, parseInt(Math.random() * (right - left + 1)) + left, right); + let indexs = part(array, left, right); quickSort(array, left, indexs[0]); quickSort(array, indexs[1] + 1, right); } @@ -305,6 +305,7 @@ function part(array, left, right) { while (left < more) { if (array[left] < array[right]) { // 当前值比基准值小,`less` 和 `left` 都加一 + less + 1 !== left && swap(array, less + 1, left); ++less; ++left; } else if (array[left] > array[right]) { @@ -378,6 +379,7 @@ function part(array, left, right) { let more = right; while (left < more) { if (array[left] < array[right]) { + less + 1 !== left && swap(array, less + 1, left); ++less; ++left; } else if (array[left] > array[right]) { @@ -644,7 +646,7 @@ function predecessor(node) { } else { let parent = node.parent // 结论 2 3 的判断 - while(parent && parent.right === node) { + while(parent && parent.right !== node) { node = parent parent = node.parent } @@ -652,9 +654,8 @@ function predecessor(node) { } } function getRight(node) { - if (!node) return - node = node.right - while(node) node = node.right + if (!node) return + while(node.right) node = node.right return node } ``` @@ -678,7 +679,7 @@ function successor(node) { // 结论 2 let parent = node.parent // 判断 parent 为空 - while(parent && parent.left === node) { + while(parent && parent.left !== node) { node = parent parent = node.parent } @@ -687,8 +688,7 @@ function successor(node) { } function getLeft(node) { if (!node) return - node = node.left - while(node) node = node.left + while(node.left) node = node.left return node } ``` diff --git a/Browser/browser-ch.md b/Browser/browser-ch.md index 52ba3e2e..d5dcbae1 100644 --- a/Browser/browser-ch.md +++ b/Browser/browser-ch.md @@ -163,8 +163,7 @@ CORS需要浏览器和后端同时支持。IE 8 和 9 需要通过 `XDomainReque // 发送消息端 window.parent.postMessage('message', 'http://test.com'); // 接收消息端 -var mc = new MessageChannel(); -mc.addEventListener('message', (event) => { +window.addEventListener('message', (event) => { var origin = event.origin || event.originalEvent.origin; if (origin === 'http://test.com') { console.log('验证通过') @@ -562,4 +561,4 @@ DOMContentLoaded 事件触发代表初始的 HTML 被完全加载和解析,不 - 将频繁运行的动画变为图层,图层能够阻止该节点回流影响别的元素。比如对于 `video` 标签,浏览器会自动将该节点变为图层。 - ![](https://yck-1254263422.cos.ap-shanghai.myqcloud.com/blog/2019-06-01-042737.png) \ No newline at end of file + ![](https://yck-1254263422.cos.ap-shanghai.myqcloud.com/blog/2019-06-01-042737.png)