Welcome! Log In Create A New Profile

Advanced

Help with errors

Posted by oscars411 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
avatar Help with errors
October 11, 2010 01:02PM
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>winking smiley'
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
avatar Re: Help with errors
October 11, 2010 03:08PM
getRoot(..) is returning a Node, not a pointer to a Node.

findMax(..) is expecting a pointer as a parameter.

Is that that problem?

(Just the usual "first thought". Someone clued up will probably arrive to help eventually).
Sorry, only registered users may post in this forum.

Click here to login