关于插入初始化update的疑惑
Author: JamesmahaitaoCreated Oct 18, 2022Updated Oct 18, 2022
跳表的插入有这样的一段代码:
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数组赋值
Source: wangzheng0822/algo