Thread: BSTree

  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, 11:02 AM
  2. Urgent help required
    By sweets in forum C++ Programming
    Replies: 3
    Last Post: 05-03-2002, 01:17 PM