AVL平衡二叉树C++操作:创建与删除;先/后/中序确定一颗二叉树
发布时间
阅读量:
阅读量
- 平衡二叉树结构
- 依据先序与后序遍历序列结合中序遍历结果可唯一确定一棵二叉树
平衡二叉树
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
struct Node {
int data;
int height;
Node* lchild;
Node* rchild;
};
/*获得该点的高度*/
int getHeight(Node* node) {
if (node == NULL) return 0;
return node->height;
}
/*求该点的平衡因子*/
int getBalanceFator(Node* node) {
return (getHeight(node->lchild) - getHeight(node->rchild));
}
/*只是更新其中高度,不需要改变结点排列,不需要取地址符号& */
void updateHeight(Node* node)
{
全部评论 (0)
还没有任何评论哟~
