Skip to content

Commit da5957e

Browse files
committed
fix skiplist test failure
1 parent 4a0da5a commit da5957e

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Advanced.Algorithms/DataStructures/List/SkipList.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ public T Find(T value)
8585
/// <param name="value">The value to insert.</param>
8686
public void Insert(T value)
8787
{
88+
if(!Find(value).Equals(default(T)))
89+
{
90+
throw new Exception("Cannot insert duplicate values.");
91+
}
92+
8893
//find the random level up to which we link the new node
8994
var level = 0;
9095
for (int i = 0; i < MaxHeight
@@ -128,11 +133,6 @@ public void Insert(T value)
128133
continue;
129134
}
130135

131-
if (current.value.CompareTo(newNode.value) == 0)
132-
{
133-
throw new Exception("Cannot insert duplicate values.");
134-
}
135-
136136
//insert and update pointers
137137
newNode.Next[i] = current.Next[i];
138138
current.Next[i] = newNode;

0 commit comments

Comments
 (0)