建立二叉树,层序、先序遍历

来源:百度知道 编辑:UC知道 时间:2024/09/20 09:26:04
用非递归算法,c++语言
1、问题描述
要求能够输入树的各个结点,并能够输出用不同方法遍历的遍历序列;分别建立建立二叉树存储结构的的输入函数、输出层序遍历序列的函数、输出先序遍历序列的函数;
2、要求
在上交资料中请写明:存储结构、基本算法(可以使用程序流程图)、源程序、测试数据和结果、算法的时间复杂度、另外可以提出算法的改进方法。

#include <iostream>
#include "sq_Queue.h"
#define M 1000
using namespace std;
template<class T>
struct Btnode
{T d;
Btnode *lchild;
Btnode *rchild;
};
template<class T>
class Binary_Tree
{private:
Btnode<T> *BT;
public:
Binary_Tree(){BT=NULL;return;}
void creat_Binary_Tree(T);
void pretrav_Binary_Tree();
void level( );
};
template<class T>
void Binary_Tree<T>::creat_Binary_Tree(T en