BSTree

This is a discussion on BSTree within the C++ Programming forums, part of the General Programming Boards category; Can anyone see what the problem with this may be? Code: template <class T> BSTree<T>& BSTree<T>::operator= (const BSTree<T>& bst) { ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    94

    BSTree

    Can anyone see what the problem with this may be?

    Code:
    template <class T>
    BSTree<T>& BSTree<T>::operator= (const BSTree<T>& bst)
    {
          if (this != &bst)
         {
                if (!isEmpty())
    	clear(root);
    
                 root=copyTree(bst.root);
          }
    
          return *this;
    }
    
    template <class T>
    BTNode<T> *copyTree (BTNode<T> *treeRoot)
    {
            BTNode<T> *newTree, *lptr, *rptr;
    
             if (treeRoot==NULL)
    	return NULL;
    
             else
              {
    	treeCopy=new BTNode<T>;
    	treeCopy->info=treeRoot->info;
    	treeCopy->lptr=copyTree(treeRoot->left);
    	treeCopy->rptr=copyTree(treeRoot->right);
              }
              return treeCopy;
    }
    simple is always an understatement.....

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    Does that code compile?

    I am confused as to what the difference is between lptr (seemingly a local variable AND member of BSTree) and left, and rptr and right (seemingly a local variable AND member of BSTree).
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. binary search trees
    By sweets in forum C++ Programming
    Replies: 3
    Last Post: 04-05-2004, 12:02 PM
  2. Urgent help required
    By sweets in forum C++ Programming
    Replies: 3
    Last Post: 05-03-2002, 02:17 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21