一个差点让我自杀的问题
二叉树的创建排序 中序遍历 有深曾的错误 希望大家指教指教#include<iostream.h>
class tree;
class node
{
private:
int age;
double grade;
node *left,*right;
friend class tree;
};
class tree
{
private:
node *root;
public:
tree(){root=NULL}
tree(int sage,int sgrade)
{
age=sage;
grade=sgrade;
}
void creat_tree()
{
if(x->age!=jiesu)
{
node *newnode=new node;
cout<<" Plase Input age :"<<endl;
cin>>InAge;
if(InAge!=jiesu)
{
cout<<" Plase Input grade:"<<endl;
cin>>InGrade;
x=new Node(InAge,InGrade);
}
newnode=x;
newnode->left=newnode->right=NULL;
if(root==NULL)
root=newnode;
else
{
tree *back;
tree *current=root;
while(current!=NULL)
{
back=current;
if(current->grade<x->grade)
current=current-left;
else
current=current->right;
}
if(back->grade>x->grade)
{back-left=newnode;}
else
{back->right=newnode;}
}
}
}
}
void inorder(tree *tmp)
{
if(tmp!=NULL)
{
inorder(tmp-left);
cout<<tmp-age<<" "<<tmp->grade<<endl;
inorder(tmp-right);
}
}
};
void main()
{
tree A;
for(int i=0;i<=9;i++)
{
A.creat_tree();
}
A.inorder(root);
}