Hello everyone,
I am learning about Binary Trees and I got stuck. I am trying to create a tree, insert the nodes and then I am planning to implement a bunch of operations but I got some errors. Here is my code, and the errors are at the end. Any information helps. I did research the errors and I think that this might have something to do with the way I named and structured things in my code.
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
class Tree
{
private:
int _value;
Tree* _left;
Tree* _right;
Tree* _root;
public:
Tree()
{}
Tree(int value, Tree* left, Tree* right)
{};
void insert(Tree* &, Tree* &);
//inserts node
void Tree::insertNode(int num)
{
Tree* newNode = nullptr; //pointer to a new node
newNode = new Tree;
newNode->value=num;
newNode->left=newNode->right=nullptr;
insert(root, newNode);
}
void Tree::insert(Tree* &nodePtr, Tree* &newNode)
{
if(nodePtr ==nullptr)
nodePtr =newNode;
else if (newNode->value < nodePtr->value)
insert(nodePtr->left, newNode);
else
{
insert(nodePtr->right, newNode);
}
}
};
int main()
{
Tree objTree;
cout<<"Inserting Nodes.\n";
objTree.insertNode(1);
objTree.insertNode(2);
objTree.insertNode(3);
objTree.insertNode(4);
objTree.insertNode(5);
objTree.insertNode(6);
objTree.insertNode(7);
objTree.insertNode(8);
objTree.insertNode(9);
return 0;
}
|
Errors:
'=' : function as left operand
'=' : function as left operand
error C2065: 'root' : undeclared identifier
error C3867: 'Tree::value': function call missing argument list; use '&Tree::value' to create a pointer to member
error C2296: '<' : illegal, left operand has type 'int (__thiscall Tree::*
error C2297: '<' : illegal, right operand has type 'int (__thiscall Tree::* )(void)'
error C3867: 'Tree::left': function call missing argument list; use '&Tree::left' to create a pointer to member
error C3867: 'Tree::right': function call missing argument list; use '&Tree::right' to create a pointer to member