2013-02-02 76 views
-4

我想在添加到列表之前检查重复项,但我无法弄清楚什么时候出错。希望你们能帮助我。我生成一个随机字符串来打印出Sign [k],例如“驴”。链接列表,添加前检查列表中的重复

代替
while (temp1 != NULL) 
{ 
    if (strcmp (static_cast <char *>((temp1 -> data)), temp)== 0) 
     return false; 

    temp1 -> next = head; 
    head = temp1; 
} 

return true; 

} 

回答

1

在你的函数testSimilar,:

temp1 -> next = head; 
head = temp1; 

你大概的意思是:

temp1 = temp1 -> next;