Creating 2nd BST
Nov 30, 2016 at 7:50am UTC
I have to create a binary search tree that when the below code is asserted it passes. the issue that i'm running into is creating the binary search tree.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
int one = 1, two = 2, three = 3, four = 4, five = 5;
BST<int > t1 = BST<int >();
BST<int > t2 = BST<int >();
//
//
// 3
// 1 4
// 0 2 5
//
t1.insert(3);
t1.insert(1);
t1.insert(0);
t1.insert(2);
t1.insert(4);
t1.insert(5);
switch (n)
case 6:
try {
t1.isMatchingTree(t2);
assert(false );
}
catch (InvalidTreeArgument) {
assert(true );
}
try {
t2.isMatchingTree(t1);
assert(false );
}
catch (InvalidTreeArgument) {
assert(true );
}
break ;
case 7:
//
// 5
// 4 30
// 2 100
//
t2.insert(5);
t2.insert(30);
t2.insert(100);
t2.insert(4);
t2.insert(2);
assert(t1.isMatchingTree(t2) == false );
assert(t
This is the function in the cpp file
1 2 3 4
bool BST<Object>::isMatchingTree(BST<Object> otherTree) const throw (InvalidTreeArgument){
bool ist = false ;
ot = otherTree;
}
h file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
template <class Object>
class BSTIterator;
template <class Object>
class BST {
public :
BST();
BST( const Object& rootElement );
BST( const BST& rhs );
~BST();
bool BST< Object >::isMatchingTree(BST< Object > otherTree) const throw (InvalidTreeArgument);
private :
typedef BST<Object> NPtr;
NPtr ot;
typedef BSTNode<Object>* NodePtr;
NodePtr root;
friend class BSTNode<Object>;
}
Error C2460 'BST<int>::ot': uses 'BST<int>', which is being defined (for ot= otherTree)
Am i going creating the tree incorrectly
Last edited on Nov 30, 2016 at 7:51am UTC
Nov 30, 2016 at 3:28pm UTC
I guess it is line 13? -> remove BST< Object >::
in front of the function.
You pass the tree as a copy which might not be a good idea.
Dec 5, 2016 at 6:32am UTC
i just found the problem is that the code, given by the instructor was incorrect he meant to pass by reference not by value. which was the main problem.
Topic archived. No new replies allowed.