问题 D: 二叉树遍历
#include<iostream> #include<algorithm> #include<vector> #include<cstring> #include<string.h> #include<queue> #include<map> #include<cmath> #define OK 1 #define ERROR 0 #define MAX 100020 const double eps=1e-5; const int maxn=1010; #define MAXSIZE 110 typedef long long LL; using namespace std; string st; typedef struct BiTNode{ char data; struct BiTNode *lchild,*rchild; }BiTNode,*BiTree; void CreateBiTree(BiTree &T,int &x){ if(st[x]=='#'){ T=NULL; } else{ T=new BiTNode; T->data=st[x]; CreateBiTree(T->lchild,++x); CreateBiTree(T->rchild,++x); } } void InOrderTraverse(BiTree T){ if(T){ InOrderTraverse(T->lchild); cout<<T->data<<" "; InOrderTraverse(T->rchild); } } int main(){ BiTree T; while(cin>>st){ int x=0; CreateBiTree(T,x); InOrderTraverse(T); cout<<endl; } return 0; }