C++ 链表,添加前检查列表中是否存在重复项
我试图在添加到列表之前检查重复项,但我不知道什么时候错了。希望你们能帮我。我生成一个随机字符串来打印符号[k],例如,驴C++ 链表,添加前检查列表中是否存在重复项,c++,C++,我试图在添加到列表之前检查重复项,但我不知道什么时候错了。希望你们能帮我。我生成一个随机字符串来打印符号[k],例如,驴 while (temp1 != NULL) { if (strcmp (static_cast <char *>((temp1 -> data)), temp)== 0) return false; temp1 -> next = head; head = temp1; } return true; }
while (temp1 != NULL)
{
if (strcmp (static_cast <char *>((temp1 -> data)), temp)== 0)
return false;
temp1 -> next = head;
head = temp1;
}
return true;
}
在您的函数测试中,类似,而不是:
temp1 -> next = head;
head = temp1;
你可能是说:
temp1 = temp1 -> next;