Skip to content

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

@Jamesmahaitao

Description

@Jamesmahaitao

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

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数组赋值

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions