通常のバイナリ ツリー (検索ではない) の「検索」および「削除」機能の作成に取り組んでいます。以下は、find 関数のコードです。
bool Find_Node(FileItem * item, Node *current ) //function starts with root
{
if (current->getNameItem() == item->getName() ) //getNameItem() retrieves the data name in node.
{
currentItem = current; //I have set currentItem as an attribute ( pointer to a Node ) in the tree class. I created it to point to the node I want to find.
return true;
}
Node* child [2];
child[0] = current->getLeft();
child[1] = current->getRight();
bool res = false;
for (int i = 0; res == false && i < 2 ; i++)
{
if(child[i] != NULL)
res = Find_Node(item, child[i]);
}
return res;
}
ノードを見つけるためのより良い方法はありますか? 誰かが削除機能を手伝ってくれるかもしれません。