Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: Binary Sear...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 2 Topic 45815 of 47017
Post > Topic >>

Re: Binary Search Tree Problems

by "Alf P. Steinbach" <alfps@[EMAIL PROTECTED] > May 9, 2008 at 12:29 AM

* pleatofthepants:
> I have a maxValue function that is called when I am removing a node
> from my tree.
> 
> template <class T>
> T BST<T> :: maxValue (TreeNode<T>* p)
> {
> 	if (p == NULL) throw ("BAD POINTER");
> 
> 		while (p-> right)
> 		{
> 			p = p-> right;
> 			return *this;
> 		}
> }
> 
> I am getting this error when it compiles: cannot convert BST<int> to
> 'int' in return
> How do I fix this?

How about trying p->value instead of *this?

There's also a problem with the placement of that return statement.

I'll leave it to you to figure it out. ;-)


Cheers, & hth.,

- Alf


PS: Preferentially reserve all uppercase identifiers for macros.  It would
also 
be a good idea to throw a standard exception object such as
std::runtime_error 
instead of anything else.  Also, to indicate the exception's origin in the

exception message.

-- 
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
 




 2 Posts in Topic:
Binary Search Tree Problems
pleatofthepants <aaron  2008-05-08 15:20:49 
Re: Binary Search Tree Problems
"Alf P. Steinbach&qu  2008-05-09 00:29:15 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 15:50:47 CDT 2008.