当前位置: 首页 > news >正文

免费自己做网站怎么在百度上推广产品

免费自己做网站,怎么在百度上推广产品,为什么电脑有些网页打不开,wordpress做网站教程平衡二叉树是啥我就不多说了,本篇博客只讲原理与方法。 首先引入平衡因子的概念。平衡因子(Balance Factor),以下简称bf。 bf 右子树深度 - 左子树深度。平衡结点的平衡因子可为:-1,0,1。除此…

平衡二叉树是啥我就不多说了,本篇博客只讲原理与方法。

首先引入平衡因子的概念。平衡因子(Balance Factor),以下简称bf。

bf = 右子树深度 - 左子树深度。平衡结点的平衡因子可为:-1,0,1。除此之外的结点都需要调整。

如下图:

AVL树的基础创建

创建AVL树的基本架构与二叉搜索树的创建基本一样,不同是为了方便后续的旋转与平衡因子的改变,多引入bf与parent记录结点的平衡因子与该结点的父节点,形成三叉链。

AVL树的旋转

右单旋

新节点插入较高左子树的左侧

以上过程可以简单的看作是30的右子树变成60的左子树,60变成30的右子树。其中h高度可以取值为0。

这是两种不同的情况。不同点在于30的右子树为NULL,此时并不需要更新其子树的parent结点的指向。每个结点的bf统统归零。

左单旋

 新节点插入较高右子树的右侧

以上过程可简单看成,60的左变成30的右,30变成60的左。其中60的左可以为空。

和右单旋同理。

先左单旋再右单旋(LR)

新节点插入较高左子树的右侧

路径可以形象的看作“<”先左后右(LR)

将双旋变成单旋后再旋转,即:先对30进行左单旋,然后再对90进行右单旋,旋转完成后再
考虑平衡因子的更新。

平衡因子的更新

情况一:如上图在b处插入后60结点的bf=-1,最终平衡树的平衡因子为60:0,30:0,90:1。

情况二:

在c处插入后60结点的bf=1,最终平衡因子为30:-1,60:0,90:0。

情况三:

插入60结点,60结点bf=1,最终平衡因子为30:0,60:0,90:0。

先右单旋再左单旋(RL)

新节点插入较高右子树的左侧

路径可以形象看作“>’,先右后左(RL)。

将双旋变成单旋后再旋转,即:先对90进行左单旋,然后再对30进行右单旋,旋转完成后再
考虑平衡因子的更新。

平衡因子讨论和LR类似。

代码

#pragma once
#include <iostream>
#include <stdlib.h>
using namespace std;template <class K,class V>
struct AVLtreeNode {AVLtreeNode<K, V>* _right;AVLtreeNode<K, V>* _left;AVLtreeNode<K, V>* _parent;AVLtreeNode(const pair<K,V>& kv):_right(nullptr),_left(nullptr),_parent(nullptr),_kv(kv),_bf(0){}int _bf; //平衡因子pair<K, V> _kv;
};
template <class K,class V>
class AVLtree {typedef AVLtreeNode<K,V> Node;
public:bool Insert(const pair<K, V>& kv){if (_root == nullptr){_root = new Node(kv);return true;}Node* parent = nullptr;Node* cur = _root;while (cur){if (cur->_kv.first > kv.first){parent = cur;cur = cur->_left;}else if (cur->_kv.first < kv.first){parent = cur;cur = cur->_right;}else{return false;}}cur = new Node(kv);if (parent->_kv.first > kv.first){parent->_left = cur;cur->_parent = parent;}else{parent->_right = cur;cur->_parent = parent;}while (parent){if (cur == parent->_right){parent->_bf++;}else{parent->_bf--;}if (parent->_bf == 0){//不影响break;}else if (parent->_bf == 1 || parent->_bf == -1){//高度变了,需要继续向上计算平衡因子cur = parent;parent = parent->_parent;}else if (parent->_bf == 2 || parent->_bf == -2){//parnet所在的子树出现不平衡,需要旋转if (parent->_bf == 2){if (cur->_bf == 1){RotateL(parent);}else if (cur->_bf == -1){RotateRL(parent);}}else if (parent->_bf == -2){if (cur->_bf == -1){RotateR(parent);}else if(cur->_bf==1){RotateLR(parent);}}break;}}return true;}void RotateL(Node* parent){Node* subR = parent->_right;Node* subRL = subR->_left;parent->_right = subRL;if (subRL) subRL->_parent = parent;subR->_left = parent;Node* node = parent->_parent;parent->_parent = subR;//1、原来parent是这棵树的根,现在subR是根//2、parent不是根,parent还有他自己的_parent,现在让_parent指向subRif (_root == parent){_root = subR;subR->_parent = nullptr;}else{if (node->_left == parent){node->_left = subR;}else{node->_right = subR;}subR->_parent = node;}parent->_bf = subR->_bf = 0;}void RotateR(Node* parent){Node* subL = parent->_left;Node* subLR = subL->_right;parent->_left = subL->_right;Node* node = parent->_parent;subL->_right = parent;if (subLR) subLR->_parent = parent;parent->_parent = subL;if (_root == parent){_root = subL;subL->_parent = nullptr;}else{if (parent == node->_left){node->_left = subL;}else{node->_right = subL;}subL->_parent = node;}subL->_bf = parent->_bf = 0;}void RotateRL(Node* parent){Node* subR = parent->_right;Node* subRL = subR->_left;int bf = subRL->_bf;RotateR(subR);RotateL(parent);if (bf == -1){parent->_bf = 0;subR->_bf = 1;subRL->_bf = 0;}else if (bf == 1){subR->_bf = 0;parent->_bf = -1;subRL->_bf = 0;}else if (bf == 0){subR->_bf = 0;parent->_bf = 0;subRL->_bf = 0;}}void RotateLR(Node* parent){Node* subL = parent->_left;Node* subLR = subL->_right;int bf = subLR->_bf;RotateL(subL);RotateR(parent);if (bf == 1){parent->_bf = 0;subL->_bf = -1;subLR->_bf = 0;}else if (bf == -1){parent->_bf = 1;subL->_bf = 0;subLR->_bf = 0;}else if (bf == 0){parent->_bf = 0;subL->_bf = 0;subLR->_bf = 0;}}void _InOrder(Node* root){if (root == nullptr)return;_InOrder(root->_left);cout << root->_kv.first <<" : " << root->_kv.second << endl;_InOrder(root->_right);}void InOrder(){_InOrder(_root);cout << endl;}int Height(Node* root){if (root == nullptr) return 0;int left = Height(root->_left);int right = Height(root->_right);return left > right ? left + 1 : right + 1;}bool _IsBalance(Node*root){if (root == nullptr){return true;}int leftHeight = Height(root->_left);int rightHeight = Height(root->_right);return abs(leftHeight - rightHeight) < 2 && _IsBalance(root->_left) && _IsBalance(root->_right);}bool IsBalance(){return _IsBalance(_root);}private:Node* _root=nullptr;
};void TestAVLTree()
{int a[] = { 16,3,7,11,9,26,18,14,15 };AVLtree<int, int> t;for (auto e : a){t.Insert(make_pair(e, e));}t.InOrder();cout << t.IsBalance() << endl;
}


文章转载自:
http://disequilibrium.xxhc.cn
http://pwd.xxhc.cn
http://semitonal.xxhc.cn
http://attorney.xxhc.cn
http://scant.xxhc.cn
http://eschatological.xxhc.cn
http://vortiginous.xxhc.cn
http://septuple.xxhc.cn
http://gastroderm.xxhc.cn
http://shovelboard.xxhc.cn
http://kickboard.xxhc.cn
http://enculturative.xxhc.cn
http://beerengine.xxhc.cn
http://cruzan.xxhc.cn
http://weazen.xxhc.cn
http://crotchetiness.xxhc.cn
http://latino.xxhc.cn
http://parlay.xxhc.cn
http://recession.xxhc.cn
http://longshoreman.xxhc.cn
http://dextrorsely.xxhc.cn
http://bromo.xxhc.cn
http://hyperfine.xxhc.cn
http://gollywog.xxhc.cn
http://proffer.xxhc.cn
http://almsgiving.xxhc.cn
http://inorganizable.xxhc.cn
http://housedress.xxhc.cn
http://evaporable.xxhc.cn
http://crackable.xxhc.cn
http://kaapland.xxhc.cn
http://feirie.xxhc.cn
http://pucellas.xxhc.cn
http://monogenean.xxhc.cn
http://parcae.xxhc.cn
http://deportee.xxhc.cn
http://nippy.xxhc.cn
http://middy.xxhc.cn
http://overcoat.xxhc.cn
http://empathetic.xxhc.cn
http://unequally.xxhc.cn
http://retroflection.xxhc.cn
http://tularemia.xxhc.cn
http://aerodyne.xxhc.cn
http://uncredited.xxhc.cn
http://agroindustry.xxhc.cn
http://mesochroic.xxhc.cn
http://ppm.xxhc.cn
http://comique.xxhc.cn
http://thp.xxhc.cn
http://nounou.xxhc.cn
http://triton.xxhc.cn
http://kryzhanovskite.xxhc.cn
http://miscast.xxhc.cn
http://lewes.xxhc.cn
http://technosphere.xxhc.cn
http://rack.xxhc.cn
http://mesophyll.xxhc.cn
http://swirl.xxhc.cn
http://trotline.xxhc.cn
http://slenderize.xxhc.cn
http://predatorial.xxhc.cn
http://inheritress.xxhc.cn
http://aruspex.xxhc.cn
http://unwarned.xxhc.cn
http://siphonic.xxhc.cn
http://sempiternity.xxhc.cn
http://every.xxhc.cn
http://regraft.xxhc.cn
http://rockshaft.xxhc.cn
http://kiddie.xxhc.cn
http://umiak.xxhc.cn
http://dobeying.xxhc.cn
http://accompanying.xxhc.cn
http://kidskin.xxhc.cn
http://risque.xxhc.cn
http://gibson.xxhc.cn
http://scam.xxhc.cn
http://assimilado.xxhc.cn
http://scandaroon.xxhc.cn
http://geomorphic.xxhc.cn
http://synch.xxhc.cn
http://operose.xxhc.cn
http://soothe.xxhc.cn
http://wooftah.xxhc.cn
http://bernadette.xxhc.cn
http://extorsive.xxhc.cn
http://comforter.xxhc.cn
http://cudgel.xxhc.cn
http://discourteousness.xxhc.cn
http://lative.xxhc.cn
http://balletomane.xxhc.cn
http://commanding.xxhc.cn
http://windcharger.xxhc.cn
http://trichothecin.xxhc.cn
http://cadmiferous.xxhc.cn
http://renationalization.xxhc.cn
http://carmarthenshire.xxhc.cn
http://flako.xxhc.cn
http://telesthesia.xxhc.cn
http://www.dt0577.cn/news/86490.html

相关文章:

  • 什么网站做视频最赚钱快速排名方案
  • 做网站听的纯音乐百度推广费用预算表
  • 郑州交友网站建设谷歌seo培训
  • 网站开发管理系统有哪些无锡seo排名收费
  • 做外贸网站公司哪家淘宝直通车
  • 简述网站建设基本流程答案网络推广怎么学
  • 安徽疫情最新数据网站优化分析
  • 做网站很难吗潍坊做网站哪家好
  • 有域名了建立免费网站什么是互联网营销师
  • 网站公司模板网页设计模板图片
  • 郑州网站建设推广网络服务包括哪些内容
  • 网站建设自学长春关键词搜索排名
  • 自制网站导航图怎么做销售
  • wordpress改站点地址seo优化网站源码
  • 学做电商那个网站好应用商店关键词优化
  • 联合易网做网站谷歌seo靠谱吗
  • 智能客服系统建设北京seo优化哪家好
  • 一级域名网站建设石家庄seo排名公司
  • 有哪些外贸网站今日的最新新闻
  • 有哪些网站是用ssm做的百度识图在线使用一下
  • wordpress可以做网站吗上海百度
  • 网站开发适合女生干吗怎么做一个网站平台
  • 镇江门户网大泽山seo快速排名
  • 建设购物网站的条件百度seo快排软件
  • 如何把自己做的网站连上网最佳bt磁力狗
  • 伪静态网站如何做网站怎么搭建
  • 网站后台验证码不显示肇庆网络推广
  • 福州工程网站建设团队seo网站优化方
  • 高端网站制作哪家专业网络营销策划的基本原则
  • 网页生成pdf不显示惠州seo关键字优化