double linked list remove duplicate | SoloLearn: Learn to code for FREE!

+1

double linked list remove duplicate

https://code.sololearn.com/c4BnHUN6S5uU hi friends here is my code removing the duplicate in double linked list for inputs like below ,i am not getting the output properly if i insert data like this 2 3 4 4 then the duplicate of 4 is not removing for other case it's removing 2 3 4 4 5 and 2 2 3 4 and 2 4 3 2 for these cases it's removing the duplicate .. please suggest me the solution

6/28/2019 1:05:55 PM

malepu rakesh

4 Answers

New Answer

+2

When you have two consecutive duplicate nodes and right of second one is NULL the condition on line 65 while(temp && temp->right!=NULL) is false and code goes to line 106 p = p->next, then back to line 60 while(p && p->right!=NULL) where the condition fails again, the loop exits, the function exits, nothing changes Also last time i asked you to use int main, you are still using void main ! Not all paths of your print function returns a value. use typedef like typedef struct _node { // declarations }node; this way you don't have to write struct node everytime. You can simply write node *ptr; Your remove function is too complex. Here is a simplified implementation for reference that does the job void remove_dup() { node *c = head; node *n = NULL; while(c != NULL && c->right != NULL) { n = c; while(n->right !=NULL) { if(c->data == n->right->data) { node* dup = n->right; n->right->left = n; n->right = n->right->right; free(dup); } else { n = n->right; } } c = c->right; } }

+2

Thank you very much ~ swim ~

+2

malepu rakesh You are Welcome ☺👍 And next time if i see void main in your code i will not reply 😉

+2

Hahahaha.......okay my dear friend