标签:图片 cas using ase std main http while struct
#include<iostream>
using namespace std;
typedef struct Node{
char data;
struct Node *lchild;
struct Node *rchild;
}BTNode, *BTree;
void PreOrder(BTree b);
void InOrder(BTree b);
void PostOrder(BTree b);
void init(BTree *b);
void CreatTree(BTree *b);
int main(){
BTree b;
init(&b);
cout<<"创建二叉树,请输入数据:(输入‘.‘则停止在该结点输入)"<<endl;
CreatTree(&b);
int i;
while(1){
cout<<"输入1:先序遍历二叉树"<<endl;
cout<<"输入2:中序遍历二叉树"<<endl;
cout<<"输入3:后序遍历二叉树"<<endl;
cout<<"输入0:退出" <<endl;
cin>>i;
switch(i){
case 1:PreOrder(b);cout<<endl;break;
case 2:InOrder(b);cout<<endl;break;
case 3:PostOrder(b);cout<<endl;break;
default :break;
}
if(i==0)
break;
}
return 0;
}
void CreatTree(BTree *b){
char a;
cin>>a;
if(a==‘.‘)
*b = NULL;
else{
(*b)=new BTNode;
(*b)->data=a;
CreatTree(&((*b)->lchild));
CreatTree(&((*b)->rchild));
}
}
void init(BTree *b)
{
*b=new BTNode;
(*b)->lchild=NULL;
(*b)->rchild=NULL;
}
void PreOrder(BTree b){
if(b!=NULL){
cout<<b->data;
PreOrder(b->lchild);
PreOrder(b->rchild);
}
}
void InOrder(BTree b){
if(b!=NULL){
InOrder(b->lchild);
cout<<b->data;
InOrder(b->rchild);
}
}
void PostOrder(BTree b){
if(b!=NULL){
PostOrder(b->lchild);
PostOrder(b->rchild);
cout<<b->data;
}
}
标签:图片 cas using ase std main http while struct
原文地址:https://www.cnblogs.com/a92412/p/10780234.html