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

二叉树

时间:2017-05-10 22:24:09      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:logs   print   class   oid   pac   treenode   ==   using   span   

#include<stdio.h>
#include<iostream>
using namespace std;
struct BitreeNode{
    int value;
    BitreeNode *left,*right;
};
BitreeNode creat(BitreeNode *&t)
{
    int ch;
    scanf("%d",&ch);
    if(ch==0) //以0为结束判断
    t=NULL;//根为则判为空树
    else
    {
        t=new BitreeNode;
        t->value=ch;
        creat(t->left);
        creat(t->right);
    }
}
void xshow(BitreeNode *t)//先序遍历 
{
    if(t!=NULL)
    {
        printf("%d\t",t->value);
        xshow(t->left);
        xshow(t->right);        
    }
}
void zshow(BitreeNode *t)//中序遍历二叉树
{
    if(t!=NULL)
    {
        zshow(t->left);
        printf("%d\t",t->value);
        zshow(t->right);        
    }
}
void hshow(BitreeNode *t)////后序遍历二叉树
{
    if(t!=NULL)
    {
        hshow(t->left);
        hshow(t->right);    
                printf("%d\t",t->value);    
    }
}
int main()
{
    BitreeNode *t;
    creat(t);
    xshow(t);
    zshow(t);
    hshow(t);
    return 0;
}        

 

二叉树

标签:logs   print   class   oid   pac   treenode   ==   using   span   

原文地址:http://www.cnblogs.com/97-ly/p/6838400.html

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