I am trying to answer some of the exam questions. But I've hit a huge snag(well at least for me it is). I am using the binarySearchTree header file & I want to write a code to find the maximum element in a tree. The problem is I need to traverse the tree from the root but there is no code to access the root node. Here is my code for the accessor function:
declaration:
nodeType<elemType> getRoot();
definition:
template<class elemType>
nodeType<elemType> bSearchTreeType<elemType>::getRoot()
{
return this->root;
}
Then I put in a function to find the maximum value of the tree nodes:
declaration:
elemType Findmax(nodeType<elemType> *p);
definition:
template<class elemType>
elemType bSearchTreeType<elemType>::Findmax(nodeType<elemType> *p)
{
if (p->rlink == NULL)
return p->info;
else
return Findmax(p->rlink);
}
This is the code I put in the application file:
max = treeRoot.Findmax(treeRoot.getRoot());
Yet I get these error messages:
error C:\unisa\mingw\bin\testProgBinarySearchTree.cpp:43 no matching function for call to `bSearchTreeType<int>::Findmax(nodeType<int>
'
note C:\unisa\mingw\bin\binarySearchTree.h:211 candidates are: elemType bSearchTreeType<elemType>::Findmax(nodeType<elemType>*) [with elemType = int]
\unisa\mingw\bin\/binarySearchTree.h C:\unisa\mingw\bin\C In member function `nodeType<elemType> bSearchTreeType<elemType>::getRoot() [with elemType = int]':
43 C:\unisa\mingw\bin\testProgBinarySearchTree.cpp instantiated from here
error C:\unisa\mingw\bin\binarySearchTree.h:206 conversion from `nodeType<int>*' to non-scalar type `nodeType<int>' requested