请高手看看这个程序哪里错了
主要功能:创建二叉排序树,中序遍历,结点取3的模,0,1,2个各输出不同的值。 2003.#include "stdafx.h"
#include<iostream>
#include"tree.h"
#define MAX 100
using namespace std;
//定义树节点的结构体
typedef struct _ml_YYY_Node
{
int data;
struct _ml_YYY_Node * lc;
struct _ml_YYY_Node * rc;
}ml_YYY_BTree;//定义树结点的结构体
//二叉排序树的类定义
class ml_YYY_CreateTree
{
public:
ml_YYY_CreateTree(int r[],int n);
virtual ~ml_YYY_CreateTree();
void ml_YYY_InSert(ml_YYY_BTree * root , ml_YYY_BTree * s);//在二叉树中插入结点
void mlYYYinOrder(ml_YYY_BTree * root);//中序遍历
private:
ml_YYY_BTree * root;
ml_YYY_BTree * s; //二叉排序树的根指针
};
//插入操作
void ml_YYY_CreateTree::ml_YYY_InSert(ml_YYY_BTree * root , ml_YYY_BTree * s)
{
if(root == NULL)
{
root = s ;
}
else if(s->data < root->data)
{
ml_YYY_InSert(root->lc , s);
}
else
{
ml_YYY_InSert(root->rc , s);
}
}
//二叉排序树的构造算法
ml_YYY_CreateTree::ml_YYY_CreateTree(int r[],int n)
{
for(int i = 0;i < n;i++)
{
s=(ml_YYY_BTree*)malloc(sizeof(ml_YYY_BTree));
if(s == NULL)
{
cout<<"Not Enough Memory!\n" ;
}
else
{
s->data = r[i];
s->lc = NULL;
s->rc = NULL;
ml_YYY_InSert( root , s);
}
}
}
//多态输出结果
class mlYYYshow
{
public:
virtual void disPlay(int n);
private:
int n;
};
class mlYYYcircleShow:public mlYYYshow
{
public:
void disPlay(int n)
{
if(n%3 == 0)
{
cout<<"Circle-"<<endl;
}
}
};
class mlYYYtriangleShow:public mlYYYshow
{
public:
void disPlay(int n)
{
if(n%3 == 1)
{
cout<<"Triangle-"<<endl;
}
}
};
class mlYYYrectangleShow:public mlYYYshow
{
public:
void disPlay(int n)
{
if(n%3 == 2)
{
cout<<"Rectangle-"<<endl;
}
}
};
//树的中序遍历算法
void ml_YYY_CreateTree:: mlYYYinOrder(ml_YYY_BTree * root)
{
if(root == NULL)
{
cout<<"the tree is null."<<endl;
}
else
{
mlYYYshow show;
mlYYYinOrder(root->lc);
show.disPlay(root->data);
mlYYYinOrder(root->rc);
}
}
void main()
{
int i,j,n;
int a[MAX];
cout<<"intput the number of the ver "<<endl;
cin >> n >>endl;
cout<<"请输入数字构造二叉树:"<<endl;
for(i=0;i<n;i++)
{
cin >> a[i] >>endl;
if(a[i] < 0 || !cin)
{
cout<<"输入有误,请重新输入数字:"<<endl;
cin.clear(); //清除错误标记
cin.get(); //清除输入缓冲区
}
}
ml_YYY_BTree * Tree ;
Tree = ml_YYY_CreateTree(a, n);
cout<<"中序遍历树,输出如下:"<<endl;
mlYYYinOrder(Tree);
}
编译的错误如下:
error C2440: '=' : cannot convert from 'ml_YYY_CreateTree' to 'ml_YYY_BTree *'No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'overloaded-function' (or there is no acceptable conversion)
error C3861: 'mlYYYinOrder': identifier not found, even with argument-dependent lookup
error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'overloaded-function' (or there is no acceptable conversion)