二叉树

#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;
}

 

posted @ 2017-05-12 14:39  编程灬世界  阅读(151)  评论(0)    收藏  举报