二叉树的前序创建
1 #include <stdio.h> 2 #define ElemType char 3 //节点声明,数据域、左孩子指针、右孩子指针 4 typedef struct BiTNode{ 5 char data; 6 struct BiTNode *lchild,*rchild; 7 }BiTNode,*BiTree; 8 //先序建立二叉树 9 BiTree CreateBiTree(){ 10 char ch; 11 BiTree T; 12 scanf("%c",&ch); 13 if(ch=='#')T=NULL; 14 else{ 15 T = (BiTree)malloc(sizeof(BiTNode)); 16 T->data = ch; 17 T->lchild = CreateBiTree(); 18 T->rchild = CreateBiTree(); 19 } 20 return T;//返回根节点 21 }