File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -160,6 +160,19 @@ else if (current == null)
160
160
current .previous = newLink ; // 1 <--> newLink <--> 2(current) <--> 3
161
161
}
162
162
}
163
+
164
+ public static void removeDuplicates (DoublyLinkedList l ) {
165
+ Link linkOne = l .head ;
166
+ while (linkOne .next != null ) { // list is present
167
+ Link linkTwo = linkOne .next ; // second link for comparison
168
+ while (linkTwo .next != null ) {
169
+ if (linkOne .value == linkTwo .value ) // if there are duplicates values then
170
+ l .delete (linkTwo .value ); // delete the link
171
+ linkTwo = linkTwo .next ; // go to next link
172
+ }
173
+ linkOne = linkOne .next ; // go to link link to iterate the whole list again
174
+ }
175
+ }
163
176
164
177
/**
165
178
* Returns true if list is empty
You can’t perform that action at this time.
0 commit comments