二叉树的建立、中序遍历(用C语言实现)

来源:百度知道 编辑:UC知道 时间:2024/05/22 13:49:03
可以用C++中的引用参数,最好别用fflush(stdin)
我这程序本来做出来的,但我不明白的是为什么一定要用fflush(stdin),否则就让我无休止地输入下去,所以望各位大虾能给我一个没有fflush(stdin)的程序.(我没学过fflush(stdin),只是在网上看到过)

#include "iostream.h"
//#include "exception.h"
//树节点类
int count=0,mode=0,data=0;

class BinaryTreeNode
{
friend class BinaryTree;
public :
BinaryTreeNode()
{
LeftChild = RightChild = 0;
}
BinaryTreeNode(const int& e)
{
data = e;
LeftChild = RightChild = 0;
}
BinaryTreeNode(const int& e, BinaryTreeNode *l,BinaryTreeNode *r)
{
data = e;
LeftChild = l;
RightChild = r;
}
private :
int data;
BinaryTreeNode *LeftChild, //左子树
*RightChild; // 右子树
} ;
class BinaryTree
{
friend class BinaryTreeNode;
public :
BinaryTree( )
{
root = 0;
}
~ BinaryTree( ) { }
bool IsEmpty( ) const
{
return ((root) ? false : true);
}
bool Root(int& x) const
{// 取根节点的d a t a域,放入x
// 如果没有根节点,则返回f a l s e
if (root)
{
x = root-&g