有个二叉树的程序
有个二叉树的程序 有四个错误 希望大家帮我调试并且讲解一下 谢谢了 我用C++写的#include<iostream.h>
struct node
{
double grade;
node *left,*right;
};
class tree
{
node *root;
public:
tree(){root=NULL;}
void create_tree(node *);
void display();
void inorder(node *);
};
void tree::create_tree(node *x)
{
node *newnode=new node;
newnode=x;
newnode->left=newnode->right=NULL;
if(root=NULL)
root=newnode;
else
{
node *current,*back;
current=root;
while(current!=NULL)
{
back=current;
if(current->left->grade>x->grade)
current=current->left;
else
current=current->right;
}
if(back->grade>x->grade)
back->left=x;
else
back->right=x;
}
void tree::inorder(node *tmp)
{
if(tmp!=NULL)
{
inorder(tmp);
cout<<tmp->grade<<endl;
inorder(tmp);
}
}
void tree::display()
{
inorder(root);
}
void main()
{
tree A;
node a[3]={{2},{4},{3}};
node *p[3]={&a[0],&a[1],&a[2]};
for(int i=0;i<=2;i++)
{
A.create_tree(p[i]);
}
A.display();
}