Removing Duplicates from Linked List
Jun 7, 2014 · Commentscode c++algolinked list
Duplicates can be removed in many ways:
Create a new Linked List containing only unique items
Iterate through the Linked List and keep removing items that are being repeated
The internal structure itself for the algo can either be map or set based. When using map the Node itself can be saved thereby making your life easier if you are creating a new Linked List. However sets can be very useful if we are just iterating through the Linked List and simply deleting items that are being repetetive. This is also a great spacesaver. Hence we decided to go down this path.
Code
As usual the code is available here:
https://github.com/abhi1010/Algorithms
Here’s a small sample as to how to do it: