2013-02-02 73 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;