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

关于插入初始化update的疑惑 #531

Open
Jamesmahaitao opened this issue Oct 18, 2022 · 0 comments
Open

关于插入初始化update的疑惑 #531

Jamesmahaitao opened this issue Oct 18, 2022 · 0 comments

Comments

@Jamesmahaitao
Copy link

跳表的插入有这样的一段代码:

Node update[] = new Node[level];
for (int i = 0; i < level; ++i) {
update[i] = head;
}
Node p = head;
// 在 update 数组中记录每一层中小于value的最大的那个value
for (int i = level - 1; i >= 0; --i) {
while (p.forwards[i] != null && p.forwards[i].data < value) {
p = p.forwards[i];
}
update[i] = p;
}

我理解

for (int i = 0; i < level; ++i) {
update[i] = head;
}

是多余的,因为下面的for循环会给各个层的update数组赋值

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant