码迷,mamicode.com
首页 > 其他好文 > 详细

二叉树

时间:2017-05-12 14:57:10      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:turn   bsp   malloc   建二叉树   return   创建   oid   str   null   

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

 

二叉树

标签:turn   bsp   malloc   建二叉树   return   创建   oid   str   null   

原文地址:http://www.cnblogs.com/sy-me/p/6845487.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!