aalhour / C-Sharp-Algorithms

:books: :chart_with_upwards_trend: Plug-and-play class-library project of standard Data Structures and Algorithms in C#
MIT License
5.91k stars 1.4k forks source link

Removing 0 from SkipList<int> breaks enumeration #138

Open Mabar16 opened 4 years ago

Mabar16 commented 4 years ago

Describe the bug Attempting to enumerate a SkipList\<int> whose head node has been removed leads to the program running indefinitely. The head can be removed by calling Remove(0), the defualt value for int, whilst the list contains a negative int.

To Reproduce Reproducing this bug can be done as follows:

  1. Instantiate a new SkipList\<int> var list = new SkipList<int>();
  2. Add any negative integer to the list list.Add(-23);
  3. Attempt to remove 0 (the head node) from the list list.Remove(0);
  4. Perform (almost) any operation that enumerates the skip list list.Contains(2);

Expected behavior list.Remove(0); should not modify the list unless 0 has been added explicitly.

Environment OS: Windows 10 Home (Version 10.0.18362 Build 18362) .NET Version: .NET Core v3.1.101 IDE: Microsoft Visual Studio Community 2019 - Version 16.4.5

Additional context

github-actions[bot] commented 4 years ago

Thanks for supporting the development of C# Algorithms with your first issue! We look forward to handling it.