I am having trouble with my binary search tree...
these are the errors i am getting - it is my print function and the find function
I have not written the code for the other print functions, i need it to compile before i can go on
bintree.h - find function
//-----------------------------------------------------------------------------
//FIND
//-----------------------------------------------------------------------------
233) template <class ItemType>
void TreeType<ItemType>::Find(ItemType& item, bool& found)
{
Retrieve(root, item, found);
}
template <class ItemType>
void Retrieve(TreeNode<ItemType>* tree, ItemType& item, bool& found)
{
if (tree == NULL)
found = false;
else if (item < tree->info)
Retrieve(tree->left, item, found);
else if (item > tree->info)
Retrieve(tree->right, item, found);
else
{
item = tree->info;
found = true;
}
}
bintree.h - PrintInOrder()
//-----------------------------------------------------------------------------
//PrintInOrder
//-----------------------------------------------------------------------------
265) template <class ItemType>
void TreeType<ItemType>::PrintInOrder(std::ostream& outFile) const
{
PrintTree(root, outFile);
}
template <class ItemType>
void PrintTree(TreeNode<ItemType>* tree, std::ofstream& outFile)
{
if (tree != NULL)
{
PrintTree(tree->left, outFile);
outFile << tree->info;
PrintTree(tree->right, outFile);
}
}
This is how i am trying to implement these in my client code
Tree.cpp - Find
else if (num == 6)
{
cout << "Enter an integer to find in the tree: ";
cin >> item;
if (tree.Find(item) == true)
cout << item << " was found";
else
cout << item << " was not found";
}
Tree.cpp - PrintInOrder
else if (num == 9)
{
tree.PrintInOrder(std::ostream& outFile);
cout << endl;
}
These are the Errors:
Tree.cpp:95: error: no matching function for call to `TreeType<int>::Find(int&)'
bintree.h:235: note: candidates are: void TreeType<ItemType>::Find(ItemType&, bool&) [with ItemType = int]
Tree.cpp:104: error: no matching function for call to `TreeType<int>::PrintInOrder()'
bintree.h:267: note: candidates are: void TreeType<ItemType>::PrintInOrder(std::ostream&) const [with ItemType = int]
Tree.cpp:116: error: expected primary-expression before '&' token
Tree.cpp:116: error: `outFile' was not declared in this scope
Tree.cpp:116: warning: unused variable 'outFile'