我正在尝试检查给定链表中是否存在实体。这是我的代码:
bool LinkedList::existByID(int ID)
{
//create node to search through the list
Node * helpNode;
//start it at the top of the list
helpNode = head;
if (head == NULL)
{
return false;
}
//while the item has not yet been found
while ((helpNode->data->indicatedEntity->getID() != ID) && (helpNode->data != NULL))
{
if (helpNode->data->indicatedEntity->getID() == ID)
{
//return true - the data exists
return true;
}
else
//if the data has not been found, move on
helpNode=helpNode->next;
}
//if the data has not been found and the end of the
//list has been reached, return false - the item does
//not exist
return false;
}
从我标记为“问题行”的行开始,if 语句的部分
(helpNode->data != NULL)
我收到错误 CXX0017(未找到符号“”)和错误 CXX0030(无法评估表达式)。
如果链表中没有实体,则此代码有效 - 换句话说,如果头为空。
Node 构造函数如下所示:
LinkedList::Node::Node()
{
next=NULL;
data=NULL;
}
我也试过了:
(helpNode != NULL)
和节点构造函数
LinkedList::Node::Node(){}
所有组合都返回相同的错误。有什么建议么?