time:2014.11.14
#include<iostream>
#include<vector>
using namespace std;
typedef struct BiTNode
{
char data;
struct BiTNode *lChild;
struct BiTNode *rChild;
}BiTNode,*BiTree;
//**********************************************************************************
//1.创建二叉树
BiTree creat()
{
char ch;
BiTree T;
ch = getchar();
if (ch == NULL)
T = NULL;
else
{
T = new BiTNode;
T->data = ch;
T->lChild = creat();
T->rChild = creat();
}
return T;
}
//*********************************************************************************
//2.打印二叉树:三种方法
//前序打印
void pre_print(BiTree T)
{
if (T)
{
cout << T->data;
pre_print(T->lChild);
pre_print(T->rChild);
}
}
//中序打印
void in_print(BiTree T)
{
if (T)
{
in_print(T->lChild);
cout << T->data;
in_print(T->rChild);
}
}
//后序打印
void post_print(BiTree T)
{
if (T)
{
post_print(T->lChild);
post_print(T->rChild);
cout << T->data;
}
}
//************************************************************************************************
//3.顶部开始逐层打印二叉树结点数据
void print_at_level(BiTNode* root)
{
vector<BiTree> vec;
vec.push_back(root);
while (vec.empty() != NULL)
{
BiTNode* tmp = vec.front();
if ((tmp->lChild) != NULL)
vec.push_back(tmp->lChild);
if ((tmp->rChild) != NULL)
vec.push_back(tmp->rChild);
cout << tmp->data;
vec.pop_back();
}
}
//**************************************************************************************************
//4.如何判断一棵二叉树是否是平衡二叉树
1838

被折叠的 条评论
为什么被折叠?



