howdy boyz n gals:
Ok here is my dilemea, i'm using my FIND function to INSERT a given data value after another given data value in a tree. Say I want 3 to be the right child of 8. So i have a find function that will find 8 in the tree, but when i compile it won't work. core dump each time. It says that it can't convert. I don't know what this means. I am pretty sure i'm returning a pointer to the node containing 8. here is my code for both the find and the insert functions.
Code:
//my public class function declarations:
template <class Comparable>
void BinarySearchTree<Comparable>::insert( const Comparable & x )
{
insert( x, root );
}
//the private version
template <class Comparable>
void BinarySearchTree<Comparable>::
insert( const Comparable & x, BinaryNode<Comparable> * & t ) const
{
if( t == NULL )
t = new BinaryNode<Comparable>( x, NULL, NULL );
else if( x < t->element )
insert( x, t->left );
else if( t->element < x )
insert( x, t->right );
else
; // Duplicate; do nothing
}
//private find function returning pointer to T
template <class Comparable>
BinaryNode<Comparable> *
BinarySearchTree<Comparable>::
find( const Comparable & x, BinaryNode<Comparable> *t ) const
{
if( t == NULL )
return NULL;
else if( x < t->element )
return find( x, t->left );
else if( t->element < x )
return find( x, t->right );
else
return t; // Match
}
//public find function
*/
template <class Comparable>
const Comparable & BinarySearchTree<Comparable>::
find( const Comparable & x ) const
{
return find( x, root ) ;
}
//THESE ARE MY ACTUAL CLASS DECLARATIONS
public:
const Comparable & find( const Comparable & x ) const;
void insert( const Comparable & x);
private:
void insert( const Comparable & x, BinaryNode<Comparable> * & t ) const; BinaryNode<Comparable> * find( const Comparable & x, BinaryNode<Comparable> *t ) const;
thanks i fried my brain all nite and couldn't figure this out...