用C++代码写二叉树的中序遍历且标明定义二叉树,要完整版

来源:百度知道 编辑:UC知道 时间:2024/06/14 18:36:11
最好还有先序和后序遍历的!!谢谢
对了,能否提供两种方法? 递归和非递归的 !!谢谢
期待您的答案!

//头文件
//*******************************************************************************
//二叉树中的数据类型为ElemType
//*******************************************************************************
// BinaryTree.h: interface for the CBinaryTree class.
//
//////////////////////////////////////////////////////////////////////
#include <iostream.h> //C++语言

#define OK 1
#define ERROR 0

class CBinaryTree
{
public:
CBinaryTree();
virtual ~CBinaryTree();

protected:
typedef int ElemType;
struct Node
{ //数据
ElemType data; //数据域信息
int lt; //前继指针标志
int rt; //后继指针标志
Node* lchild; //指向左孩子
Node* rchild; //指向右孩子
}*root,*head;

public:
int Create();
int PreOrderTraverse();
int MidOrderTraverse();
int LastOrderTraverse();
void LevelOrderTraverse();
int GetLeafCount();
int GetDepth();