所以我試着去實現一個令2 B樹但是我很新的節目,特別是在C++中,我創建了這個結構的每個節點B樹搜索引用兒童的數據類型問題
struct BTreeNode
{
int data[2];
BTreeNode **ChildLow;
BTreeNode **ChildMid;
BTreeNode **ChildHigh;
};
所以,當我嘗試和設置下一個節點搜索作爲孩子,我不斷收到編譯錯誤,它需要它的類型BTreeNode,它是不是?
bool search(BTreeNode *root, int value)
{
BTreeNode currentNode = *root;
bool found = false;
bool searchComplete = false;
while(found == false || searchComplete == false)
{
if (currentNode == NULL)
{
searchComplete == true;
return false;
}
if (currentNode.data[1] == value)
{
found == true;
}
else if(value > currentNode.data[1])
{
if (currentNode.data[2] == value)
{
found == true;
}
else if(value > currentNode.data[2])
{
currentNode == currentNode.ChildHigh;
}
else
{
currentNode == currentNode.ChildMid;
}
}
else
{
currentNode == currentNode.ChildLow;
}
}
}
當我將它與null比較時,它也顯示一個錯誤。
下面是錯誤:
1 IntelliSense: no operator "==" matches these operands
operand types are: BTreeNode == int
2 IntelliSense: no operator "==" matches these operands
operand types are: BTreeNode == BTreeNode **
3 IntelliSense: no operator "==" matches these operands
operand types are: BTreeNode == BTreeNode **
4 IntelliSense: no operator "==" matches these operands
operand types are: BTreeNode == BTreeNode **
1爲空的錯誤,其餘爲指針,以兒童
任何幫助,將不勝感激
謝謝
編譯錯誤既不會動搖也不會拋出,它們會被打印出來,如果您需要任何幫助,您需要在這裏打印它們,在您的問題中。 – EJP
@ user3105172我已經發布了一個更新的答案,它應該擺脫你的錯誤,雖然我認爲你應該有BTreeNode * childHigh而不是BTreeNode ** childHigh的結構。 –
你的聲明中額外的間接級別的目的是什麼:'BTreeNode ** ChildLow;'?而且這三個名字真的妨礙了簡單的編碼。用'BTreeNode * Children'[3];' – JSF