我的问题是关于从链接列表中删除重复项。但我想在添加到链接列表之前执行此操作。添加之前删除链接列表中的重复项 - C
struct myStr{int number; mystr *next;}
void append(mystr **q,int item)
{
myStr *temp;
temp = *q;
myStr *newone;
if(*q==NULL)// There should be control of previous elements. Call of keysearch function.
{ temp = (myStr *)malloc(sizeof(myStr));
temp->number =size;
temp->next=NULL;
*q=temp;
}
else //And also here
{ temp = *q;
while(temp->next !=NULL)
{ temp=temp->next;
}
newone = (myStr *)malloc(sizeof(myStr));
newone->count = size;
newone->next=NULL;
temp->next=newone;
}
}
int keysearch (myStr *p)
{
struct myStr *temp = p;
int found = 0;
int key= p->number;
while (temp->next != NULL)
{
if(temp->number == key)
{
return 1;
//break;
}
temp = temp->next;
}
return 0;
}
我的问题是在keySearch。我不知道什么是错的?或者有另一种方法来做到这一点。
你是@LuckySlevin? http://stackoverflow.com/questions/2840228的代码在风格和命名约定中看起来与此非常相似。 – Phil 2010-05-15 14:54:27
这看起来可疑类似于这个问题:http://stackoverflow.com/questions/2840228/appending-unique-values-only-in-a-linked-list-in-c - 代码几乎完全相同。很好的尝试改变变量名称。 – interjay 2010-05-15 14:54:55
@菲尔我认为只有几个人在做同样的任务,我们一定会最终看到这一点。 @DesperateCoders - 如果是家庭作业,请将其标记为家庭作业。 – 2010-05-15 14:59:07