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)
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 ;
You can’t perform that action at this time.
0 commit comments