how to write a function that removes all duplicated notes from a Circular Doubly Linked List.
<code>NODE *RemoveDuplicates(NODE *p, NODE *q);</code>
where p points to the first node, and q to the last
thanks
how to write a function that removes all duplicated notes from a Circular Doubly Linked List.
<code>NODE *RemoveDuplicates(NODE *p, NODE *q);</code>
where p points to the first node, and q to the last
thanks
I did it like tis:
Is there any better way?Code:NODE* Remove_Duplicates(NODE *p, NODE **q) { NODE *tmp, *tmp1; NODE *n; /* checking for Empty list */ if (p==NULL) return; tmp1=p; while (p!=tmp1->prev) { n=p->next; while (n!=tmp1) { if (n->data==p->data) { n->prev->next=n->next; n->next->prev=n->prev; tmp=n; n=n->next; free(tmp); } else n=n->next; } p=p->next; } return tmp1; }
You don't seem to use the q parameter.
What do you mean 'better'?
Better named variables might help understanding it perhaps.
n, tmp, tmp1 hardly make for good reading.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Well as salem said u are not using Q any where there. Instead u can use the pointer to pointer on P so that can avoid returning pointer P in you function
ssharish2005