Skip to content

Fix SkipList remove operation #3160

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

Merged

Conversation

Boiarshinov
Copy link
Contributor

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

References

There was a failed build: https://github.com/TheAlgorithms/Java/runs/6992142297?check_suite_focus=true

After some debugging I have found the problem. After removing some node all links for previous and next node should be reassigned. But current algorithm did not mentioned that next node could be null. For example (on this structure tests had failed in linked build):

[ ] --- --- --- --- --- --- --- --- --- --- --- 
[ ] --- --- --- --- --- --- --- --- --- --- --- 
[ ] [ ] --- --- --- --- --- --- --- --- --- --- 
[ ] [ ] --- --- --- --- --- --- --- --- --- --- 
[ ] [ ] --- --- --- --- --- --- --- [ ] --- --- 
[ ] [ ] --- --- [ ] --- [ ] --- --- [ ] --- --- 
[ ] [ ] [ ] --- [ ] --- [ ] --- --- [ ] --- --- 
[ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] 
 H   0   1   2   3   4   5   6   7   8   9  10

When we try to delete node with index 0, it would have null next nodes on layers 4 and 5.

I had fixed an issue and add test case with removing last node. So removing elements with pointers to null is tested separately now.

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All functions and variable names follow Java naming conventions.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

@Boiarshinov Boiarshinov force-pushed the fix_skiplist_remove_method branch from 768dc4b to 69ac6ca Compare June 22, 2022 06:20
@Boiarshinov Boiarshinov mentioned this pull request Jun 22, 2022
7 tasks
@yanglbme yanglbme merged commit d14a5d1 into TheAlgorithms:master Jun 22, 2022
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

Successfully merging this pull request may close these issues.

2 participants