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

温州建站程序创建网站的基本流程

温州建站程序,创建网站的基本流程,哪个网站可以免费建站,wordpress调用上传附件学了很久编程了,红黑树在我们耳边早就如雷贯耳,都说他是数据结构中最难的几种结构了,但是,实际上学会了之后,你会发现他还是很简单的,个人认为他还没有AVL树的旋转难,好了,老规矩&am…

学了很久编程了,红黑树在我们耳边早就如雷贯耳,都说他是数据结构中最难的几种结构了,但是,实际上学会了之后,你会发现他还是很简单的,个人认为他还没有AVL树的旋转难,好了,老规矩,来上代码:

#pragma once
#pragma once
#include <iostream>
#include <set>
#include <map>
#include <assert.h>
#include <math.h>
#include <vector>
using namespace std;
namespace cc
{enum colour{RED,BLACK};template<class K, class V>struct RBtreenode{colour _col;pair<K, V> _val;RBtreenode<K, V>* _left;RBtreenode<K, V>* _right;RBtreenode<K, V>* _parent;RBtreenode(const pair<K, V>& x):_val(x), _left(nullptr), _right(nullptr), _parent(nullptr), _col(RED){}};template<class K, class V>class RBtree{public:typedef RBtreenode<K, V> node;void reor(node* parent){node* sub = parent->_left;node* subr = sub->_right;if (_root == parent){_root = sub;sub->_parent = nullptr;sub->_right = parent;parent->_parent = sub;parent->_left = subr;if (subr)subr->_parent = parent;}else{node* pparent = parent->_parent;if (pparent->_left == parent)pparent->_left = sub;elsepparent->_right = sub;sub->_parent = pparent;sub->_right = parent;parent->_parent = sub;parent->_left = subr;if (subr)subr->_parent = parent;}}void reol(node* parent){node* sub = parent->_right;node* subl = sub->_left;if (_root == parent){_root = sub;sub->_parent = nullptr;sub->_left = parent;parent->_parent = sub;parent->_right = subl;if (subl)subl->_parent = parent;}else{node* pparent = parent->_parent;if (pparent->_left = parent)pparent->_left = sub;elsepparent->_right = sub;sub->_parent = pparent;sub->_left = parent;parent->_parent = sub;parent->_right = subl;if (subl)subl->_parent = parent;}}bool insert(const pair<K, V>& x){if (_root == nullptr){_root = new node(x);_root->_col = BLACK;return true;}node* parent = nullptr;node* cur = _root;while (cur){if (x.first < cur->_val.first){parent = cur;cur = cur->_left;}else if (x.first > cur->_val.first){parent = cur;cur = cur->_right;}elsereturn false;}cur = new node(x);if (parent->_val.first > x.first)parent->_left = cur;elseparent->_right = cur;cur->_parent = parent;node* grandfather = parent->_parent;while (parent && parent->_col == RED){if (grandfather->_left == parent){node* uncle = grandfather->_right;//情况一:只染色if (uncle && uncle->_col == RED){uncle->_col = BLACK;parent->_col = BLACK;grandfather->_col = RED;if (grandfather == _root){grandfather->_col = BLACK;break;}}//情况二+三:旋转+染色else if (uncle && uncle->_col == BLACK){if (parent->_left == cur){//单旋reor(grandfather);//染色grandfather->_col = RED;parent->_col = BLACK;}else{//双旋reol(parent);reor(grandfather);//染色cur->_col = BLACK;//爷爷节点变红grandfather->_col = RED;}break;}else if (uncle == nullptr){if (parent->_left == cur){reor(grandfather);grandfather->_col = RED;parent->_col = BLACK;}else{reol(parent);reor(grandfather);grandfather->_col = RED;cur->_col = BLACK;}break;}}else{node* uncle = grandfather->_left;if (uncle && uncle->_col == RED){uncle->_col = BLACK;parent->_col = BLACK;grandfather->_col = RED;if (_root == grandfather){grandfather->_col = BLACK;break;}}else if (uncle && uncle->_col == BLACK){if (parent->_left == cur){reor(parent);reol(grandfather);grandfather->_col = RED;cur->_col = BLACK;}else{reol(grandfather);grandfather->_col = RED;parent->_col = BLACK;}break;}else if (uncle == nullptr){if (parent->_left = cur){reor(parent);reol(grandfather);cur->_col = BLACK;grandfather->_col = RED;}else{reol(grandfather);parent->_col = BLACK;grandfather->_col = RED;}break;}}cur = grandfather;parent = cur->_parent;grandfather = parent->_parent;}return true;}bool check(){return _check(_root);}void print(){prin(_root);}void prin(node* root,int num){if (root == nullptr)return;if (root->_col == BLACK)num++;if (root->_left == root->_right &&root->_left == nullptr)cout << num << endl;prin(root->_left,num);prin(root->_right,num);}bool _check(node* root){if (root == nullptr){if (root->_col != BLACK)exit(-1);return true;}if (root->_parent && root->_parent->_col == RED){cout << "异常退出" << endl;exit(-1);}int num = 0;prin(root, num);}private:node* _root = nullptr;};
}

其实和AVL树的代码差不多,唯一不同的是,我们没有平衡因子了,但是有颜色。

下面来说说红黑树的规则:

1.一个节点不是红色就是黑色

2.根节点必须是黑色

3.红色节点的两个孩子必须是黑色节点

4.每条路径的黑色节点个数相同

5.叶子结点(NIL节点)是黑色的

上面就是红黑树的规则,红黑树的代码就在上面,现在说一下红黑树的具体实现规则:

1.如果叔叔节点存在且叔叔节点为红色,那么,把父节点和叔叔节点染成黑色,组父节点染成红色,如果此时的祖父节点是根节点,那么,就在把祖父节点染成黑色。如果不是,就把新插入的节点更新成祖父节点,依次往上更新,直到父节点为空或是父节点的颜色为黑色就停止。

2.如果叔叔节点存在,且叔叔节点是黑色的,那么此时就要判断新插入的节点在父节点的左还右,如果父节点,祖父节点,新插入的节点成一条线,那么此时就是单旋,然后旋转完成之后把父节点染成黑色,祖父节点染成红色。

3.如果叔叔节点存在,且为黑色,新插入节点与父节点,祖父节点形成折线,那么此时应该是双旋,旋转完成之后,把新插入的节点染成黑色,祖父节点染成红色。

4.如果叔叔节点不存在,那就看是上面的额那种情况,是那种旋转,找到对应的旋转就好了。

以上就是实现红黑树代码的具体细节。

AVL树和红黑树的对比:

其实AVL树和红黑树两个各有各的好处,是的,个人认为两个各有各的好处,因为AVL对树高比较严格,所以导致旋转点额次数就多,所以就会有额外的消耗,但是红黑树就没有这么多的消耗了,因为红黑树的上面几个规则,导致红黑树最长路径不得超过对短路径的两倍,所以,红黑树也会旋转,但是插入同等节点的条件下,红黑树旋转点次数肯定比AVL树少,但是AVL树是严格的logn,而红黑树是不太严格的logn,所以我说是各有各的好。

以上就是红黑树的规则讲解以及代码实现。希望大家能够多多支持!!谢谢!


文章转载自:
http://skywriting.jqLx.cn
http://laevoglucose.jqLx.cn
http://importee.jqLx.cn
http://metalled.jqLx.cn
http://lilium.jqLx.cn
http://tome.jqLx.cn
http://antianginal.jqLx.cn
http://madid.jqLx.cn
http://serape.jqLx.cn
http://thermolabile.jqLx.cn
http://anemometry.jqLx.cn
http://flower.jqLx.cn
http://ither.jqLx.cn
http://myocardium.jqLx.cn
http://linzertorte.jqLx.cn
http://worldwide.jqLx.cn
http://paviour.jqLx.cn
http://copycutter.jqLx.cn
http://mithraist.jqLx.cn
http://twp.jqLx.cn
http://neglectful.jqLx.cn
http://teknonymy.jqLx.cn
http://villus.jqLx.cn
http://bunnia.jqLx.cn
http://pox.jqLx.cn
http://spoffish.jqLx.cn
http://swampy.jqLx.cn
http://devilwood.jqLx.cn
http://contract.jqLx.cn
http://diopside.jqLx.cn
http://jig.jqLx.cn
http://illinois.jqLx.cn
http://postbase.jqLx.cn
http://buckish.jqLx.cn
http://calamite.jqLx.cn
http://gownsman.jqLx.cn
http://eradicative.jqLx.cn
http://choirmaster.jqLx.cn
http://diamondback.jqLx.cn
http://tishri.jqLx.cn
http://lucianic.jqLx.cn
http://unpleasable.jqLx.cn
http://alumina.jqLx.cn
http://calgon.jqLx.cn
http://illegitimate.jqLx.cn
http://algum.jqLx.cn
http://toluene.jqLx.cn
http://largely.jqLx.cn
http://doodad.jqLx.cn
http://sickee.jqLx.cn
http://ruggerite.jqLx.cn
http://emblazonry.jqLx.cn
http://aleatory.jqLx.cn
http://macroinstruction.jqLx.cn
http://unsent.jqLx.cn
http://insulator.jqLx.cn
http://reimprison.jqLx.cn
http://earthshock.jqLx.cn
http://whipless.jqLx.cn
http://option.jqLx.cn
http://scraggy.jqLx.cn
http://unitable.jqLx.cn
http://enunciable.jqLx.cn
http://rhadamanthine.jqLx.cn
http://hospitaler.jqLx.cn
http://beaten.jqLx.cn
http://androcles.jqLx.cn
http://soapstone.jqLx.cn
http://tideway.jqLx.cn
http://biathlon.jqLx.cn
http://oxysome.jqLx.cn
http://nonresident.jqLx.cn
http://antibishop.jqLx.cn
http://coolish.jqLx.cn
http://suchou.jqLx.cn
http://praxis.jqLx.cn
http://obi.jqLx.cn
http://dyn.jqLx.cn
http://silverbeater.jqLx.cn
http://bathtub.jqLx.cn
http://illegible.jqLx.cn
http://makable.jqLx.cn
http://singularly.jqLx.cn
http://expertize.jqLx.cn
http://spruce.jqLx.cn
http://hera.jqLx.cn
http://deduction.jqLx.cn
http://thiocyanate.jqLx.cn
http://vivify.jqLx.cn
http://nankeen.jqLx.cn
http://dithyramb.jqLx.cn
http://fabricable.jqLx.cn
http://serif.jqLx.cn
http://helminthic.jqLx.cn
http://mosfet.jqLx.cn
http://volcanism.jqLx.cn
http://kinetic.jqLx.cn
http://hollowness.jqLx.cn
http://passionful.jqLx.cn
http://reading.jqLx.cn
http://www.hrbkazy.com/news/86542.html

相关文章:

  • 龙岩做网站改版找哪家公司谷歌搜索引擎营销
  • 玩家世界网站建设微信推广软件哪个好
  • 企业网站设计特点值得收藏的五个搜索引擎
  • 优秀的营销策划案例广州网站优化服务
  • 高端网站开发公司seo必备软件
  • 济南哪家公司可以做网站竞价广告代运营
  • jianshe导航网站廊坊seo建站
  • 平台门户网站建设方案百度今日排行榜
  • 做社区网站用什么程序搜索广告优化
  • wordpress标题去掉私密哈尔滨关键词优化方式
  • 宁波企业名称查询网站网络营销的推广
  • 做素材网站赚钱吗郑州最新通告
  • 天津宇昊建设集团有限公司网站百度浏览器官网入口
  • 网站制作和收费标准网站关键词免费优化
  • 做自己的网站需要多少钱微信推广软件有哪些
  • app手机端电子商务网站功能深圳seo教程
  • 北京做网站推广上海谷歌seo推广公司
  • 网络营销策划论文惠州企业网站seo
  • 什么网站可以免费做兼职百度热点榜单
  • 奉贤区做网站进入百度首页
  • 软件开发用的软件seo和sem的联系
  • 西安住房和城乡建设局网站免费接单平台
  • 华为云做网站不能修改页面企业文化建设方案
  • 海南政务服务网平台优化是什么意思
  • 网站的ftp上传地址宁波seo关键词优化教程
  • 济南专业做网站近期新闻事件
  • 济南网站建设app百度一下官网首页网址
  • html设计主题网站代码国家职业技能培训学校
  • 室内设计怎么样广州seo快速排名
  • 税务新闻网站建设的意义女排联赛排名