```c++ //遍歷演算法 #include using namespace std; typedef struct BiNode{ char data; struct BiNode *lchild,*rchild; }BiTNode,*BiTree; void CreratBiTree(BiTre... ...
可能編譯時會有些語法小錯誤(比如分號,->,等),很容易就自己糾正了哦,思路絕對是完全正確的,所以用的話就自己試著改改吧,直接複製粘貼,就正確,豈不是太沒寫代碼體驗了,自己改改才印象更加深刻的呢(^▽^)~~~~;
//遍歷演算法
#include<iostream>
using namespace std;
typedef struct BiNode{
char data;
struct BiNode *lchild,*rchild;
}BiTNode,*BiTree;
void CreratBiTree(BiTree &T){
char ch;
cin>>ch;
if(ch=='#') T=NULL;
else{
T=new BiTree;
T->data=ch;
CreratBiTree(T->lchild);
CreratBiTree(T->rchild)
}
}
void InOderTraverserve(BiTree T){
if(T){
InOderTraverserve(T->lchild);
cout<<T-data;
InOderTraverserve(T->rchild);
}
}
void main(){
BiTree tree;
cout<<"please input\n";
CreratBiTree(tree);
cout<<"middle result\n";
CreratBiTree(tree);
cout<<"front result\n";
cout<<endl;
}