Thread: removing dups from a linked list

  1. #1
    Registered User brianptodd's Avatar
    Join Date
    Oct 2002

    removing dups from a linked list

    How can I remove nodes with duplicate data from a linked list. I am having trouble writing the while loop.
    "In theory, there is no difference between theory and practice. But, in practice, there is."
    - Jan L.A. van de Snepscheut

  2. #2
    Join Date
    Sep 2003
    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.
    The information given in this message is known to work on FreeBSD 4.8 STABLE.
    *The above statement is false if I was too lazy to test it.*
    Please take note that I am not a technical writer, nor do I care to become one.
    If someone finds a mistake, gleaming error or typo, do me a favor...bite me.
    Don't assume that I'm ever entirely serious or entirely joking.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. singly linked to doubly linked
    By jsbeckton in forum C Programming
    Replies: 10
    Last Post: 11-06-2005, 07:47 PM
  2. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  3. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 05:46 PM
  4. Template Class for Linked List
    By pecymanski in forum C++ Programming
    Replies: 2
    Last Post: 12-04-2001, 09:07 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM