How can I remove nodes with duplicate data from a linked list. I am having trouble writing the while loop.
Printable View
How can I remove nodes with duplicate data from a linked list. I am having trouble writing the while loop.
Walk through the list and when you encounter a new node, add it to another list. When you run out of new nodes (ie. each node you encounter in the old list already exists in the new list), you've removed all the duplicates. Or you can do it the same way you would with an array: Walk through the list, for each node walk through the list again searching for duplicates, if you find any, remove them.