Skip to content

Commit

Permalink
Fixed Issue aalhour#139 A new SkipList<int> contains 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Gutsonok committed Aug 5, 2020
1 parent f769be0 commit 9cab153
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 7 additions & 3 deletions DataStructures/Lists/SkipList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,20 @@ public bool Remove(T item, out T deleted)
/// </summary>
public bool Contains(T item)
{
T itemOut;
return Find(item, out itemOut);
return Find(item, out var _);
}

/// <summary>
/// Look for an element and return it if found
/// </summary>
public bool Find(T item, out T result)
{
result = default;
if(IsEmpty)
{
return false;
}

var current = _firstNode;

// Walk after all the nodes that have values less than the node we are looking for
Expand All @@ -219,7 +224,6 @@ public bool Find(T item, out T result)
return true;
}

result = default(T);
return false;
}

Expand Down
10 changes: 10 additions & 0 deletions UnitTest/DataStructuresTests/SkipListTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ namespace UnitTest.DataStructuresTests
{
public static class SkipListTest
{
[Fact]
public static void EmptyList()
{
var skipList = new SkipList<int>();

Assert.True(skipList.Count == 0);
Assert.True(skipList.IsEmpty);
Assert.DoesNotContain(0, skipList);
}

[Fact]
public static void AddOneElement()
{
Expand Down

0 comments on commit 9cab153

Please sign in to comment.