We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0389d31 commit fc8e36cCopy full SHA for fc8e36c
DataStructures/Lists/DoublyLinkedList.java
@@ -160,6 +160,19 @@ else if (current == null)
160
current.previous = newLink; // 1 <--> newLink <--> 2(current) <--> 3
161
}
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
176
177
/**
178
* Returns true if list is empty
0 commit comments