Hello everyone.I am having trouble with my code. I'm trying to make it compile but I'm having no luck. Can someone help me compile my code? Thank you in advance.
#ifndef MY_BTREE_H
#define MY_BTREE_H
// my_btree.h - binary tree class (no balancing)
usingnamespace std;
// forward declaration of classes defined in this header
template <class T> class btree;
template <class T> class node;
template <class T>
class btree
{
public:
// constructors
btree(); // no-arg constructor
btree(const btree & tree); // copy constructor
~btree(); // destructor
// operations
bool empty() const;
int size() const;
T & root() const;
// print in-order traversal of the tree
void print() const;
// insert x into tree (wherever it goes)
void add_element(const T & x);
// calculate height of tree
int height() const;
protected:
node<T> * rootnode;
unsignedint my_size;
// internal methods used recursively
private:
// calculate height of a tree rooted at n
int height(node<T> *n) const;
// print subtree rooted at n (recursive)
void print(node<T> *n);
// insert x in tree rooted at node n (keep in order!)
void insert(node<T> * n, const T & x);
};
template <class T>
class node
{
private:
node(const T & x); // private constructor
T x; // data
node<T> * left; // left child
node<T> * right; // right child
friendclass btree<T>;
};
#include "my_btree.cpp"
#endif
my_btree.cpp:7: error: expected constructor, destructor, or type conversion before ‘<’ token
my_btree.cpp:12: error: expected constructor, destructor, or type conversion before ‘<’ token
my_btree.cpp:17: error: expected constructor, destructor, or type conversion before ‘<’ token
my_btree.cpp:22: error: expected initializer before ‘<’ token
my_btree.cpp:27: error: expected initializer before ‘<’ token
my_btree.cpp:32: error: expected initializer before ‘<’ token
my_btree.cpp:37: error: expected initializer before ‘<’ token
my_btree.cpp:42: error: expected initializer before ‘<’ token
my_btree.cpp:47: error: expected initializer before ‘<’ token
my_btree.cpp:52: error: expected initializer before ‘<’ token
my_btree.cpp:57: error: expected initializer before ‘<’ token
my_btree.cpp:62: error: expected initializer before ‘<’ token
my_btree.cpp:67: error: expected initializer before ‘<’ token
my_btree.cpp:72: error: ‘node’ has not been declared
my_btree.cpp:72: error: ISO C++ forbids declaration of ‘node’ with no type
my_btree.cpp:77: error: expected constructor, destructor, or type conversion before ‘<’ token
Thank you for your help but its still not working. I forgot to mention that i cannot alter the .h file. I still keep getting the same errors i was getting earlier. Can you still help me figure it out?
I wish i could put the #include "my_btree.h" into the .cpp but im not allowed to. Is there a way you can help me with the error messages? I don't think im calling them properly. Thanks.