二叉树的操作.docVIP

  • 11
  • 0
  • 约4.79千字
  • 约 6页
  • 2019-09-27 发布于江苏
  • 举报
#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; void CreateBiTree(BiTree T){//按先序次序输入,构造二叉链表表示的二叉树T,空格表示空树 // if(T) return; char ch; ch=getchar(); //不能用cin来输入,在cin中不能识别空格。 if(ch== ) T=NULL; else{ if(!(T=(BTNode *)malloc(sizeof(BTNode)))) coutmalloc fail!; T-data=ch; CreateBiTree(T-lchild); CreateBiTree(T-rchild); } } void PreOrderTraverse(BiTree T){//先序遍历 if(T){ coutT-data ; PreOrderTraverse(T-lchild); P

文档评论(0)

1亿VIP精品文档

相关文档