C++版二叉树的操作.docVIP

  • 11
  • 0
  • 约4.71千字
  • 约 6页
  • 2018-04-23 发布于河南
  • 举报
C版二叉树的操作

#include iostream.h #include stdlib.h #include stdio.h typedef char ElemType;//定义二叉树结点值的类型为字符型 const int MaxLength=10;//结点个数不超过10个 typedef struct BTNode{ ElemType data; struct BTNode *lchild,*rchild; }BTNode,* BiTree; BiTree CreateBiTree(){//按先序次序输入,构造二叉链表表示的二叉树T,空格表示空树 BiTree T; char ch; ch=getchar(); //不能用cin来输入,在cin中不能识别空格。 if(ch==0) T=NULL; else{ if(!(T=(BTNode *)malloc(sizeof(BTNode)))) coutmalloc fail!; T-data=ch; T-lchild=CreateBiTree(); T-rchild=CreateBiTree(); } return T; } void PreOrderTraverse(BiTree T){//先序遍历 if(T){ coutT-data ; PreOrderTraverse(T-lchild); Pr

文档评论(0)

1亿VIP精品文档

相关文档