二叉树的建立学习笔记

    xiaoxiao2026-10-04  3

    http://blog.sina.com.cn/s/blog_a19e8c1b01016m2v.html

    #include <stdio.h>

    #define ElemType char

    //节点声明,数据域、左孩子指针、右孩子指针

    typedef struct BiTNode{

        char data;

        struct BiTNode *lchild,*rchild;

    }BiTNode,*BiTree;

    //先序建立二叉树

    BiTree CreateBiTree(){

        char ch;

        BiTree T;

        scanf("%c",&ch);

        if(ch=='#')T=NULL;

        else{

            T = (BiTree)malloc(sizeof(BiTNode));

            T->data = ch;

            T->lchild = CreateBiTree();

            T->rchild = CreateBiTree();

        }

        return T;//返回根节点

    }

    转载请注明原文地址: https://ju.6miu.com/read-1312620.html
    最新回复(0)