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

跳表删除元素更新levelCount异常 #464

Open
wyc192273 opened this issue Apr 1, 2020 · 2 comments
Open

跳表删除元素更新levelCount异常 #464

wyc192273 opened this issue Apr 1, 2020 · 2 comments

Comments

@wyc192273
Copy link

由于老师的代码,在levelCount-1处是有值的,如果如老师代码所写
while (levelCount>1&&head.forwards[levelCount]==null){ levelCount--; }
则,跳表中node的maxLevel会与外层的levelCount不一致
正确代码应该是:
while (levelCount>1&&head.forwards[levelCount-1]==null){ levelCount--; }

@evilkevinhe
Copy link

多遍历了一次而已也不会有数组越界的问题

@Sjunhao
Copy link

Sjunhao commented Apr 26, 2022

老师原来代码删除确实会有问题的,我在项目中使用跳表,原来的代码会在使用randomLevel()后导致程序出现随机的删除失效的问题。经过排查,改成该ISSUE的代码可以正确删除。

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

3 participants