标签:c++
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> using namespace std; typedef struct Binode{ char data; struct Binode *lchild,*rchild; }Binode,*Bitree; void CreatTREE(Bitree &T) { char ch; scanf("%c",&ch); if(ch==' ') { T=NULL; } else { T=(Bitree)malloc(sizeof(Binode)); T->data=ch; CreatTREE(T->lchild); CreatTREE(T->rchild); } return; } void print_pre(Bitree &T) { if((T!=NULL)) { printf("%c ",T->data); print_pre(T->lchild); print_pre(T->rchild); } return; } void print_in(Bitree &T) { if(T!=NULL) { print_in(T->lchild); printf("%c ",T->data); print_in(T->rchild); } return; } void print_after(Bitree &T) { if(T!=NULL) { print_after(T->lchild); print_after(T->rchild); printf("%c ",T->data); } } int main() { Bitree T; CreatTREE(T); print_pre(T); cout<<endl; print_in(T); cout<<endl; print_after(T); cout<<endl; return 0; }
标签:c++
原文地址:http://blog.csdn.net/axuan_k/article/details/41146319