template <class T>
Node<T>* BinaryTree<T>::getFather(Node<T>* current)
{
Node<T>* temp = root;
while(temp != NULL || !traverseStack.isEmpty())
{
if(temp)
{
if(temp->leftChild == current || temp->rightChild == current)
{
return temp;
}
if(temp->rightChild)
{
traverseStack.pushStack(temp->rightChild);
}
temp = temp->leftChild;
}
else
{
traverseStack.popStack(temp);
}
}
return NULL;
}
而我已经用 if(temp),程序中temp为无法读取,那就不应该进入if语句,为什么程序还是执行if后面的语句了?
無法讀取是指標異常,不代表指標為0
你的root沒有初始化吧。
temp的值是一個位址值,只要位址值不為0,if都會通過。
資訊量太少了 不好判斷
鄧俊輝的資料結構? 這種書都有原始碼的 去官網上下
NULL現在推薦使用nullptr