创建一颗二叉树的方法

#include <stdio.h>

typedef struct BiTNode{

char data;

struct BiTNode *lchild,*rchild;

}BiTNode,*BiTree;

CreateBiTree(BiTree *T)

{

char c;

scanf(“%c”,&c);

if(‘ ‘ == c)

{

*T = NULL;

}

else

{

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

(*T)->data = c;

CreateBiTree(&(*T)->lchild);

CreateBiTree(&(*T)->rchild);

}

}

visit(char c,int level)

{

printf(“%c位于第几%d层\n”,c,level);

}

PreOrederTraverse(BiTree T,int level)

{

if(T)

{

visit(T->data,level);

PreOrederTraverse(T->lchild,level+1);

PreOrederTraverse(T->rchild,level+1);

}

}

void main(){

int level=1;

BiTree *T = NULL;

CreateBiTree(&T);

PreOrederTraverse(T,level);

    原文作者:B树
    原文地址: https://blog.csdn.net/B_G_boy/article/details/79532035
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞