-1
我正在尝试为需要输入并将其放入二进制树的学校中的课程创建程序。当我编译我得到错误“无法转换'树**'到'树*'在作业中”。它编译我是否注释掉InsertNode方法。无法在作业中将'树**'转换为'树*'
//The main method to create the tree
void CreateTree()
{
char list[MAX_SIZE];
string line;
getline(cin,line);
strcpy(list,line.c_str());
cout << list << endl;
Tree* root = new Tree;
root->data = list[0];
root->right = NULL;
root->left = NULL;
for(int i=1; i<MAX_SIZE; i++)
{
InsertNode(root, list[i]);
}
}
//The method to insert the next char into the tree
void InsertNode(Tree* root, char n)
{
Tree* curr = &root; //the error is here
if(curr==NULL)
curr->data=n;
else if(curr->data<=n)
{
curr=curr->right;
InsertNode(root, n);
}
else if(curr->data>n)
{
curr=curr->left;
InsertNode(root, n);
}
}
我意识到其他一些代码可能无法按预期工作,但我只是想帮助我收到的错误。