摘要: //删除叶子节点 void Delete_leaf(BTNode *t){ if(t==null) return; if(t->lchild!=null){ BTNode* tlchild=t->lchild; if(tlchild->lchild==null && t->trchild==null 阅读全文
posted @ 2019-12-23 13:05 ZzUuOo666 阅读(2185) 评论(0) 推荐(0) 编辑
摘要: //已知先序和中序建立一颗二叉树 void CreateTree(BTTree t,int[] pre,int[] in, int l1,int h1,int l2,int h2){//l1 为先序数组的第一个,h1 为先序数组的最后一个 int i; T=(BTNode*)malloc(sizeo 阅读全文
posted @ 2019-12-23 13:04 ZzUuOo666 阅读(398) 评论(0) 推荐(0) 编辑
摘要: //同时统计叶子节点数和非叶子节点数 10 void Count(BTNode *t,int &num1,int &num2){ if(t==null) return; else{ if(t->lchild==null && t->rchild==null){ num1++; }else{ num2 阅读全文
posted @ 2019-12-23 13:03 ZzUuOo666 阅读(1044) 评论(0) 推荐(1) 编辑
摘要: //判断两棵树是否相似 树形一样 数值不一样 8 bool IsSimilar(BTNode *t1,BTNode *t2){ if(t1==null && t2==null) return true; if(t1==null || t2==null) return false; else{ ret 阅读全文
posted @ 2019-12-23 13:02 ZzUuOo666 阅读(1297) 评论(0) 推荐(0) 编辑
摘要: //判断是否为BST 搜索树==二叉排序树 1、递归知最大最小值。2、先中序判是否单调 bool IsValidBST(BTNode *p,int low,int high){ if(p==NULL){ return true; }else{ if(low<p->data && high>p->da 阅读全文
posted @ 2019-12-23 13:01 ZzUuOo666 阅读(430) 评论(0) 推荐(0) 编辑
摘要: //让树所有叶子节点连成一个单链表,让rchild作为 next指针 LNode *head=null,*pre=null;//全局变量 LNode *InOrder(BTNode *T){ if(T!=null){ InOrder(T->lchild); if(T->lchild==null && 阅读全文
posted @ 2019-12-23 12:58 ZzUuOo666 阅读(384) 评论(0) 推荐(0) 编辑
摘要: //递归遍历二叉树 void levelOrder(BTNode *T){ if(T==null) return; int height=getHeight(T); for(int i=1;i<height;i++){ _levelOrder(T,i); } } void _levelOrder(B 阅读全文
posted @ 2019-12-23 12:55 ZzUuOo666 阅读(751) 评论(0) 推荐(0) 编辑