二叉树问题
我花了好几个星期 也没整出来 希望各位高手指点指点吧 程序源代码如下:创建的同时排序 然后中序列遍历史 这样就能按从小到大的顺序输出了 程序有3个错误 希望大家能帮帮我 急啊!#include<iostream.h>
struct node
{
double grade;
node *left,*right;
};
class tree
{
node *root;
public:
tree(){root=NULL;}
void create_tree(double);
void display();
void inorder(node *);
};
void tree::create_tree(double x)
{
node *newnode=new node;
cout<<"input the grade of x:"<<endl;
cin>>x;
newnode->grade=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)
current=current->left;
else
current=current->right;
}
if(back->grade>x)
back->left=newnode;
else
back->right=newnode;
}
}
void tree::inorder(node *tmp)
{
if(tmp!=NULL)
{
inorder(tmp->left);
cout<<tmp->grade<<endl;
inorder(tmp->right);
}
void tree::display()
{
inorder(root);
}
void main()
{
tree A;
A.display();
}