File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed
Advanced.Algorithms/DataStructures/List Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -85,6 +85,11 @@ public T Find(T value)
85
85
/// <param name="value">The value to insert.</param>
86
86
public void Insert ( T value )
87
87
{
88
+ if ( ! Find ( value ) . Equals ( default ( T ) ) )
89
+ {
90
+ throw new Exception ( "Cannot insert duplicate values." ) ;
91
+ }
92
+
88
93
//find the random level up to which we link the new node
89
94
var level = 0 ;
90
95
for ( int i = 0 ; i < MaxHeight
@@ -128,11 +133,6 @@ public void Insert(T value)
128
133
continue ;
129
134
}
130
135
131
- if ( current . value . CompareTo ( newNode . value ) == 0 )
132
- {
133
- throw new Exception ( "Cannot insert duplicate values." ) ;
134
- }
135
-
136
136
//insert and update pointers
137
137
newNode . Next [ i ] = current . Next [ i ] ;
138
138
current . Next [ i ] = newNode ;
You can’t perform that action at this time.
0 commit comments