遍历二叉树

贡献者:断桥残雪 类别:代码 时间:2017-04-04 19:20:31 收藏数:50 评分:-0.5
返回上页 举报此文章
请选择举报理由:




收藏到我的文章 改错字
#include<iostream>
using namespace std;
struct BiTNode{
char data;
struct BiTNode* lchild,* rchild;
};
void CreatBiTree(BiTNode* &T){
char ch;
for (int j = 0; j < 13; ++j) {
if((ch=getchar()) == '#')
T = NULL;
else{
T = new BiTNode;
T->data = ch;
CreatBiTree(T->lchild);
CreatBiTree(T->rchild);
}
}
}
void PreOrderTraverse(BiTNode* &T){
if(T){
cout << T->data;
PreOrderTraverse(T->lchild);
PreOrderTraverse(T->rchild);
}
else
cout << "";
}
void Inoder(BiTNode* &T){
if(T){
Inoder(T->lchild);
cout << T->data;
Inoder(T->rchild);
}
else
cout << "";
}
void Posoder(BiTNode* &T){
if(T){
Posoder(T->lchild);
Posoder(T->rchild);
cout << T->data;
}
else
cout << "";
}
int main(){
cout << "Create Tree:" << endl;
BiTNode* T;
CreatBiTree(T);
cout << "Before" << endl;
PreOrderTraverse(T);
cout << "Infix" << endl;
Inoder(T);
cout << "Postorder" << endl;
Posoder(T);
return 1;
}
声明:以上文章均为用户自行添加,仅供打字交流使用,不代表本站观点,本站不承担任何法律责任,特此声明!如果有侵犯到您的权利,请及时联系我们删除。
文章热度:
文章难度:
文章质量:
说明:系统根据文章的热度、难度、质量自动认证,已认证的文章将参与打字排名!

本文打字排名TOP20

登录后可见

用户更多文章推荐