mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-10 04:26:27 +08:00
Merge pull request #1292 from moetezz/moetezz
added removeDuplicates() function
This commit is contained in:
@ -161,6 +161,19 @@ public class DoublyLinkedList {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void removeDuplicates(DoublyLinkedList l ) {
|
||||||
|
Link linkOne = l.head ;
|
||||||
|
while(linkOne.next != null) { // list is present
|
||||||
|
Link linkTwo = linkOne.next; // second link for comparison
|
||||||
|
while(linkTwo.next!= null) {
|
||||||
|
if(linkOne.value == linkTwo.value) // if there are duplicates values then
|
||||||
|
l.delete(linkTwo.value); // delete the link
|
||||||
|
linkTwo = linkTwo.next ; // go to next link
|
||||||
|
}
|
||||||
|
linkOne = linkOne.next; // go to link link to iterate the whole list again
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if list is empty
|
* Returns true if list is empty
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user