二叉树遍历
#include<iostream> #include<queue> using namespace std; typedef struct Bnode { int data; struct Bnode *lchild,*rchild; }Bnode,*Btree; void Createtree(Btree &T)//创建二叉树 { char ch; cin>>ch; if(ch=='#') T=NULL;//递归结束,建立空树 else { T=new Bnode; T->data=ch;//生成根节点 Createtree(T->lchild);//生成左子树 Createtree(T->rchild);//生成右子树 } } void preorder(Btree T)//先序 { if(T) { cout<<T->data<<" "; preorder(T->lchild); preorder(T->rchild); } } void inorder(Btree T)//中序 { if(T) { inorder(T->lchild); cout<<T->data<<" "; inorder(T->rchild); } } void posorder(Btree T)//后序 { if(T) { posorder(T->lchild); posorder(T->rchild); cout<<T->data<<" "; } } int main() { return 0; }