Click here to Skip to main content
15,910,981 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionDuplicates in list Pin
sadas232341s18-Apr-11 8:28
sadas232341s18-Apr-11 8:28 
AnswerRe: Duplicates in list Pin
Chris Losinger18-Apr-11 9:18
professionalChris Losinger18-Apr-11 9:18 
GeneralRe: Duplicates in list Pin
sadas232341s18-Apr-11 9:20
sadas232341s18-Apr-11 9:20 
GeneralRe: Duplicates in list Pin
Chris Losinger18-Apr-11 9:27
professionalChris Losinger18-Apr-11 9:27 
GeneralRe: Duplicates in list Pin
sadas232341s18-Apr-11 9:29
sadas232341s18-Apr-11 9:29 
GeneralRe: Duplicates in list Pin
Chris Losinger18-Apr-11 9:38
professionalChris Losinger18-Apr-11 9:38 
GeneralRe: Duplicates in list Pin
sadas232341s18-Apr-11 9:39
sadas232341s18-Apr-11 9:39 
AnswerRe: Duplicates in list Pin
Luc Pattyn18-Apr-11 9:53
sitebuilderLuc Pattyn18-Apr-11 9:53 
You do not need to actually sort the list, since that would mean you first compare a lot of them and move around some nodes, then remove some (the duplicates). That is too much effort for what is needed.

What you need to do is compare a lot and remove, but never move. In pseudo-code (always solve an algorithmic problem in pseudo-code first):
foreach(Node n1) {
    foreach (Node n2 before n1) {
        if (n2.value==n1.value) {
            remove(n1);
            break;
        }
    }
}


Smile | :)

PS: and that could be done on a single-linked list as well, as both loops are enumerating from the start and never need to go backward.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

GeneralRe: Duplicates in list Pin
sadas232341s18-Apr-11 9:58
sadas232341s18-Apr-11 9:58 
GeneralRe: Duplicates in list Pin
Chris Losinger18-Apr-11 10:02
professionalChris Losinger18-Apr-11 10:02 
GeneralRe: Duplicates in list Pin
sadas232341s18-Apr-11 10:13
sadas232341s18-Apr-11 10:13 
GeneralRe: Duplicates in list Pin
David Crow18-Apr-11 18:02
David Crow18-Apr-11 18:02 
GeneralRe: Duplicates in list Pin
sadas232341s18-Apr-11 9:54
sadas232341s18-Apr-11 9:54 
GeneralRe: Duplicates in list Pin
Chris Losinger18-Apr-11 10:14
professionalChris Losinger18-Apr-11 10:14 
GeneralRe: Duplicates in list Pin
sadas232341s18-Apr-11 10:16
sadas232341s18-Apr-11 10:16 
GeneralRe: Duplicates in list Pin
Chris Losinger18-Apr-11 10:19
professionalChris Losinger18-Apr-11 10:19 
GeneralRe: Duplicates in list Pin
sadas232341s18-Apr-11 10:25
sadas232341s18-Apr-11 10:25 
GeneralRe: Duplicates in list Pin
sadas232341s18-Apr-11 10:32
sadas232341s18-Apr-11 10:32 
GeneralRe: Duplicates in list Pin
Chris Losinger18-Apr-11 10:50
professionalChris Losinger18-Apr-11 10:50 
GeneralRe: Duplicates in list [modified] Pin
sadas232341s18-Apr-11 10:51
sadas232341s18-Apr-11 10:51 
GeneralRe: Duplicates in list Pin
Chris Losinger18-Apr-11 11:03
professionalChris Losinger18-Apr-11 11:03 
QuestionCritique is Need Pin
Ikeman from Moses Lake18-Apr-11 7:09
Ikeman from Moses Lake18-Apr-11 7:09 
Question[SOLVED] I need to copy (CTRL+C) a web page... C++ [modified] Pin
Ram Shmider18-Apr-11 1:43
Ram Shmider18-Apr-11 1:43 
AnswerRe: I need to copy (CTRL+C) a web page... C++ Pin
_AnsHUMAN_ 18-Apr-11 2:20
_AnsHUMAN_ 18-Apr-11 2:20 
GeneralRe: I need to copy (CTRL+C) a web page... C++ Pin
Ram Shmider19-Apr-11 20:20
Ram Shmider19-Apr-11 20:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.