#include <stdio.h> #include <stdlib.h> typedef struct tree { char data; struct tree * L, *R; }Tree; void creat(Tree **T)//创建二叉树 { char ch; if ((ch=getchar())==‘#‘) *T=NULL; else { *T=(Tree *)malloc(sizeof(Tree)); (*T)->data=ch; creat(&((*T)->L)); creat(&((*T)->R)); } } void vist(Tree **T)//先序遍历 { if (*T) { printf("%c ",(*T)->data); vist(&((*T)->L)); vist(&((*T)->R)); } } int main() { Tree *T=NULL; creat(&T); vist(&T); return 0; }
原文:http://www.cnblogs.com/sy-me/p/6845487.html