I am trying to insert elements in a binary search tree.I am getting the following errors:
In member function 'void bst::insert(char*)':
error: cannot convert 'char*' to 'node*' in assignment
error: cannot convert 'node*' to 'const char*' for argument '1' to 'int strcmp(const char*, const char*)'
In function 'int main()':
error: 'A' was not declared in this scope
//code//
#include<iostream>
using namespace std;
class node
{
public:
char string[100];
node *left_child;
node *right_child;
node();
~node();
};
node::node()
{
left_child = NULL;
right_child = NULL;
}
node::~node()
{
}
class bst
{
public:
void insert(char *str);
//void display_preorder(char *str);
};
void bst::insert(char *str)
{
node *obj;
obj = new node();
if (strcmp(obj->string,str)<0)
{
if (obj->right_child == NULL)
{
obj->right_child = str;
}
else if(strcmp(obj->right_child,str)<0)
{
obj->right_child = str;
}
else
{
obj->left_child = str;
}
}
}
int main()
{
bst *obj1;
obj1 = new bst();
obj1->insert(A);
obj1->insert(B);
return 0;
}