| | |
Search and delete duplicates in linked list
![]() |
•
•
Join Date: Dec 2007
Posts: 7
Reputation:
Solved Threads: 0
Hello, guys!
I have the following code: So I experience difficulties when implementing the removing duplicates part. What I tried to do is: get (each) word from list, strcmpit to next words, remove if duplicate found. Here is my solution: But something is wrong. It compiles without errors, but doesn't say anything about duplicates, even though I know there are. Thanks in advance!
I have the following code:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct list_word
{
char word[64];
struct list_word * next;
};
typedef struct list_word itemWord;
int main()
{
itemWord * curr, * head;
fill list with words
remove duplicates
show final list of words
return(0);
} C Syntax (Toggle Plain Text)
curr = head; while(curr) { strcpy(check,curr->word); curr = curr->next; while(curr) { if(strcmp(check,curr->word)==0) printf("duplicate"); {here should come the remove node function} curr = curr->next; } }
Last edited by simps0n; Apr 23rd, 2008 at 8:21 am.
you need to keep two different pointers for curr because you have two different loops. Try this:
C Syntax (Toggle Plain Text)
curr1 = head; while(curr1) { strcpy(check,curr1->word); curr2 = curr1->next; while(curr2) { if(strcmp(check,curr2->word)==0) printf("duplicate"); {here should come the remove node function} curr2 = curr2->next; } cur1 = cur1->next; }
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
> Old Thread, but what the heck..
Like reading the rules, but what the heck heh?
http://www.daniweb.com/forums/thread78060.html
"Don't resurrect old threads!"
Like reading the rules, but what the heck heh?
http://www.daniweb.com/forums/thread78060.html
"Don't resurrect old threads!"
![]() |
Similar Threads
Other Threads in the C Forum
- Previous Thread: Help with my row counter
- Next Thread: Vi and ctags
| Thread Tools | Search this Thread |
#include adobe ansi api array asterisks binarysearch changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory dynamic execv feet fgets file fork forloop frequency function getlasterror givemetehcodez global grade graphics gtkgcurlcompiling hacking hardware highest histogram i/o include incrementoperators infiniteloop input interest kernel keyboard kilometer license linked linkedlist linux linuxsegmentationfault list locate logical_drives looping loopinsideloop. lowest match matrix meter microsoft motherboard mqqueue mysql number odf opensource owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing scanf segmentationfault sequential shape socket socketprograming standard string systemcall threads turboc unix user voidmain() wab windows.h windowsapi






