二叉树递归建立

#include <iostream>


typedef struct BinaryTreeNode
{
    int key;
    struct BinaryTreeNode *ltree;
    struct BinaryTreeNode *rtree;
}BinaryTreeNode;

static BinaryTreeNode *create_binary_tree();

int main(int argc, char *argv[])
{
    BinaryTreeNode *root_tree;
    root_tree = create_binary_tree();
    
    return 0;
}

/*先序递归建立二叉树.*/
static BinaryTreeNode *create_binary_tree()
{
    int c;
    BinaryTreeNode *tree;

    std::cin>>c;
    if (c == -1)
        return NULL;
    else
    {
        tree = new BinaryTreeNode;
        tree->key = c;
        tree->ltree = create_binary_tree();
        tree->rtree = create_binary_tree();
        return tree;
    }
}

 

posted @ 2014-10-15 22:59  yyxayz  阅读(200)  评论(0编辑  收藏  举报