
c++ 二叉树
碳酸钙的01妖精
这个作者很懒,什么都没留下…
展开
-
二叉树遍历模板
typedef struct Node{ char data; struct Node* LChild; struct Node* RChild;}BiTNode,*PBiTNode;//先序遍历void PreOrder(BiTNode* root){ if(root != NULL) { cout<<root->data; PreOrder(root->LChild); PreOrder.原创 2020-10-09 15:02:50 · 274 阅读 · 0 评论 -
建立与遍历中序线索树
PBiTNode pre; //全局变量会分配一个静态空间,和NULL不是同一个void Inthread(PBiTNode root) //初始pre取NULL{ //对root所指的二叉树进行中序线索化,其中pre始终指向刚访问过的结点,其初值为NULL if(root!=NULL) { Inthread(root->LChild); //线索化左子树 if(root->LChild==NULL) //置前驱线索 .原创 2020-09-22 21:25:24 · 332 阅读 · 0 评论 -
后序遍历与先序遍历求二叉树的高度
//后序遍历求二叉树高度//后序要求的值的变化从底向上int PostTreeDepth(PBiTNode bt){ int hl,hr,maxn; if(bt!=NULL) { hl=PostTreeDepth(bt->LChild); hr=PostTreeDepth(bt->RChild); maxn=hl>hr?hl:hr; return maxn+1; } else..原创 2020-09-22 18:58:16 · 1929 阅读 · 0 评论 -
P1087 FBI树(二叉树+先序遍历构树+后序遍历输出)
P1087 FBI树(二叉树+先序遍历构树+后序遍历输出)#include<cstdio>#include<iostream>using namespace std;//二叉树的元素一定是偶数(废话)char str[2000];int n;void binarytree(int x,int y){ int i; if(y>x) ...原创 2018-03-25 14:30:13 · 761 阅读 · 0 评论 -
建立二叉树的二叉链表(已知先序和中序,求后序)
建立二叉树的二叉链表(已知先序和中序,求后序)#include <stdio.h>#include <stdlib.h>#include <string.h> //原理:由前序和中序可以确定唯一的二叉树typedef struct Node{ char Data; struct Node* LChild; struct Node* RCh...原创 2018-06-20 08:51:10 · 1297 阅读 · 0 评论 -
哈夫曼编/译码器
哈夫曼编/译码器#include <stdio.h>#include <stdlib.h>#include <string.h>int MAXN=0x3f3f3f3f;char* HC[120]; //指针的指针就全局处理,子函数就不用传,方便struct HtNode{ int weight; int parent; int Lchild;...原创 2018-06-20 12:02:53 · 240 阅读 · 0 评论 -
建立二叉树的二叉链的存储结构((先序遍历创建+先序遍历输出))
建立二叉树的二叉链的存储结构#include <stdio.h>#include <stdlib.h>#include <string.h>typedef struct Node{ char Data; struct Node* LChild; struct Node* RChild;}BiTNode,*PBiTNode;void Create...原创 2018-06-20 08:51:35 · 960 阅读 · 0 评论 -
计算二叉树叶子结点数目(先序遍历创建+先序遍历输出)
计算二叉树叶子结点数目#include <stdio.h>#include <stdlib.h>#include <string.h>typedef struct Node{ char Data; struct Node* LChild; struct Node* RChild;}BiTNode,*PBiTNode;int cnt=0;void...原创 2018-06-20 08:51:48 · 3026 阅读 · 0 评论 -
输出以二叉树表示的算术表达式(先序遍历创建+中序遍历输出)
输出以二叉树表示的算术表达式#include <stdio.h>#include <stdlib.h>#include <string.h>typedef struct Node{ char Data; struct Node* LChild; struct Node* RChild; //先序遍历创建}BiTNode,*PB...原创 2018-06-20 08:52:29 · 2317 阅读 · 0 评论