1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #include <stdio.h> #include <stdlib.h> typedef struct tree { char t; struct tree *lchild; struct tree *rchild; }Tree; void initTree(Tree **T) { char ch; ch = getchar(); if (ch == '#') { *T = NULL; } else { *T = (Tree *)malloc(sizeof(Tree)); (*T)->t = ch; initTree(&(*T)->lchild); initTree(&(*T)->rchild); } } void qianT(Tree *T) { if (T) { printf("%c ",T->t); qianT(T->lchild); qianT(T->rchild); } } int main (void) { Tree *T; initTree(&T); qianT(T); return 0; } </stdlib.h></stdio.h> |
1 2 3 4 5 6 7 8 9 10 11 12 13 | void initTree(Tree *T) { char ch; ch = getchar(); if (ch == '#') { T = NULL; } else { T = (Tree *)malloc(sizeof(Tree)); T->t = ch; initTree(T->lchild); initTree(T->rchild); } } |
欢迎光临 滴水逆向联盟 (http://www.dtdebug.com/) | Powered by Discuz! X3.2 |