网址:http://zju.acmclub.com/index.php?app=problem_title&id=1&problem_id=1757
非常非常简单:
#include<stdio.h> #include<malloc.h> typedef struct node { char data; node *Lchild; node *Rchild; }Tree; void CreateTree(Tree *&T) { char key; scanf("%c",&key); if(key == ' ') { T = NULL; } else { T = (Tree *)malloc(sizeof(Tree)); T->data = key; CreateTree(T->Lchild); CreateTree(T->Rchild); } } void Pre(Tree *T) { if(T != NULL) { printf("%c ",T->data); Pre(T->Lchild); Pre(T->Rchild); } } void Mid(Tree *T) { if(T != NULL) { Mid(T->Lchild); printf("%c ",T->data); Mid(T->Rchild); } } int main() { Tree *T; CreateTree(T); Pre(T); printf("\n"); Mid(T); printf("\n"); Mid(T); printf("\n"); return 0; }