Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:quick-sort-code-mistakes #193

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Algorithm/algorithm-ch.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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]) {
Expand Down Expand Up @@ -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]) {
Expand Down Expand Up @@ -644,17 +646,16 @@ 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
}
return parent
}
}
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
}
```
Expand All @@ -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
}
Expand All @@ -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
}
```
Expand Down
5 changes: 2 additions & 3 deletions Browser/browser-ch.md
Original file line number Diff line number Diff line change
Expand Up @@ -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('验证通过')
Expand Down Expand Up @@ -562,4 +561,4 @@ DOMContentLoaded 事件触发代表初始的 HTML 被完全加载和解析,不

- 将频繁运行的动画变为图层,图层能够阻止该节点回流影响别的元素。比如对于 `video` 标签,浏览器会自动将该节点变为图层。

![](https://yck-1254263422.cos.ap-shanghai.myqcloud.com/blog/2019-06-01-042737.png)
![](https://yck-1254263422.cos.ap-shanghai.myqcloud.com/blog/2019-06-01-042737.png)