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

淘宝接网站开发的活秘密入口3秒自动进入

淘宝接网站开发的活,秘密入口3秒自动进入,横店八上信息书做网站的内容,网站开发程序排名目录 资源已上传 实现代码 测试代码 资源已上传 部分图片 实现代码 注意判断是否为红黑树的代码实现&#xff0c;实现代码中红黑树的删除 #pragma once #include<iostream> using namespace std;enum Color_Type {Red,Black };template<class K,class V> str…

目录

资源已上传

实现代码

测试代码


资源已上传

部分图片

实现代码

注意判断是否为红黑树的代码实现,实现代码中红黑树的删除

#pragma once
#include<iostream>
using namespace std;enum Color_Type
{Red,Black
};template<class K,class V>
struct RBTreeNode
{pair<K, V> _kv;RBTreeNode* _parent;RBTreeNode* _left;RBTreeNode* _right;Color_Type _color;RBTreeNode(const pair<K, V> kv): _kv(kv), _parent(nullptr), _left(nullptr), _right(nullptr), _color(Red){}};template<class K, class V>
class RBTree
{typedef RBTreeNode<K, V> Node;
private:Node* _root;
public:RBTree():_root(nullptr){}bool Insert(const pair<K, V>& kv){if (_root == nullptr){_root = new Node(kv);_root->_color = Black;return true;}Node* cur = _root;//指向当前节点的位置Node* parent = nullptr;//当前节点的父节点//找到插入位置while (cur){if (cur->_kv.first < kv.first) {parent = cur;cur = cur->_right;}else if (cur->_kv.first > kv.first) {parent = cur;cur = cur->_left;}else {return false;}}cur = new Node(kv);cur->_color = Red;if (cur->_kv.first < parent->_kv.first) {parent->_left = cur;cur->_parent = parent;}else{parent->_right = cur;cur->_parent = parent;}//父节点为红色,插入后还需做调整while (parent && parent->_color == Red){Node* grandfather = parent->_parent;if (parent == grandfather->_left){Node* uncle = grandfather->_right;if (uncle && uncle->_color == Red){// 变色parent->_color = uncle->_color = Black;grandfather->_color = Red;// 继续向上处理cur = grandfather;parent = cur->_parent;}else//uncle不存在或uncle为黑{if (cur == parent->_left){//	  g//	p//crotateR(grandfather);parent->_color = Black;grandfather->_color = Red;}else{//	g//p	//	crotateL(parent);rotateR(grandfather);cur->_color = Black;grandfather->_color = Red;}break;}}else{Node* uncle = grandfather->_left;// u存在且为红if (uncle && uncle->_color == Red){// 变色parent->_color = uncle->_color = Black;grandfather->_color = Red;// 继续向上处理cur = grandfather;parent = cur->_parent;}else{if (cur == parent->_right){// g//	  p//       crotateL(grandfather);grandfather->_color = Red;parent->_color = Black;}else{// g//	  p// crotateR(parent);rotateL(grandfather);cur->_color = Black;grandfather->_color = Red;}break;}}}_root->_color = Black;return true;}bool IsBalance(){return _IsBalance(_root);}int Height(){return _Height(_root);}bool checkColor(Node* root, int blacknum, int basenum){if (root == nullptr){if (blacknum != basenum){return false;}return true;}if (root->_color == Black){++blacknum;}if (root->_parent && root->_parent->_color == Red && root->_color == Red){cout << root->_kv.first << "出现连续红色节点" << endl;return false;}return  checkColor(root->_left, blacknum, basenum) && checkColor(root->_right, blacknum, basenum);}
private:void rotateL(Node* parent){Node* subR = parent->_right;Node* subRL = subR->_left;Node* pparent = parent->_parent;//1.建立subRL与parent之间的关系//左子树滑动parent->_right = subRL;if (subRL) {subRL->_parent = parent;}//2.建立subR和parent之间的关系//更新右子树的左子树subR->_left = parent;parent->_parent = subR;//3.建立pparent和subR之间的关系//与上一个节点建立连接if (parent == _root){_root = subR;subR->_parent == nullptr;}else{subR->_parent = pparent;if (parent = pparent->_left) {pparent->_left = subR;}else {pparent->_right = subR;}}}void rotateR(Node* parent){Node* subL = parent->_left;Node* subLR = subL->_right;Node* pparent = parent->_parent;//滑动parent->_left = subLR;if (subLR) {subLR->_parent = parent;}//更新左子树的右子树subL->_right = parent;parent->_parent = subL;if (parent == _root) {_root = subL;subL->_parent = nullptr;}else {subL->_parent == pparent;if (parent = pparent->_left) {pparent->_left = subL;}else {pparent->_right = subL;}}}int _Height(Node* root){if (!root) {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;}if (root->_color != Black){return false;}int basenum = 0;Node* cur = _root;while (cur){if (cur->_color == Black) {++basenum;}cur = cur->_left;}return checkColor(root, 0, basenum);}};

测试代码

#include "RB_tree.h"
#include<vector>int main()
{const int N = 10;vector<int> v;v.reserve(N);srand(time(0));for (size_t i = 0; i < N; i++){v.push_back(i);}for (auto i : v){cout << i << " ";}cout << endl;RBTree<int, int> rbt;for (auto e : v){rbt.Insert(make_pair(e, e));cout << "Insert:" << e << endl;}cout << rbt.Height() << endl;if (rbt.IsBalance()){cout << "ok" << endl;}return 0;
}


文章转载自:
http://nisroch.c7622.cn
http://housebound.c7622.cn
http://breathlessly.c7622.cn
http://aerodontalgia.c7622.cn
http://proverbial.c7622.cn
http://homologic.c7622.cn
http://tolerance.c7622.cn
http://speedballer.c7622.cn
http://uncoil.c7622.cn
http://perisperm.c7622.cn
http://infauna.c7622.cn
http://cicatrize.c7622.cn
http://diaphoneme.c7622.cn
http://messenger.c7622.cn
http://shouting.c7622.cn
http://polymer.c7622.cn
http://cyanidation.c7622.cn
http://incitant.c7622.cn
http://rosanna.c7622.cn
http://jesuitry.c7622.cn
http://popshop.c7622.cn
http://guyot.c7622.cn
http://pawnbroking.c7622.cn
http://unconsciously.c7622.cn
http://brochure.c7622.cn
http://reductase.c7622.cn
http://jackeroo.c7622.cn
http://agglomerant.c7622.cn
http://prolixity.c7622.cn
http://predicable.c7622.cn
http://foramen.c7622.cn
http://allopurinol.c7622.cn
http://complexional.c7622.cn
http://telson.c7622.cn
http://ratafee.c7622.cn
http://forktail.c7622.cn
http://disemployment.c7622.cn
http://fertile.c7622.cn
http://nonpsychotic.c7622.cn
http://outmaneuver.c7622.cn
http://gradgrind.c7622.cn
http://sickener.c7622.cn
http://atlanticist.c7622.cn
http://ejectment.c7622.cn
http://busily.c7622.cn
http://chymotrypsinogen.c7622.cn
http://chainman.c7622.cn
http://rattleroot.c7622.cn
http://marl.c7622.cn
http://hyposthenic.c7622.cn
http://agamete.c7622.cn
http://alcoholic.c7622.cn
http://exfacie.c7622.cn
http://eosphorite.c7622.cn
http://stotious.c7622.cn
http://acmeist.c7622.cn
http://literatim.c7622.cn
http://idiom.c7622.cn
http://enjoyment.c7622.cn
http://stockjobbing.c7622.cn
http://hammock.c7622.cn
http://pantry.c7622.cn
http://sirvente.c7622.cn
http://unsheltered.c7622.cn
http://supplemental.c7622.cn
http://fourth.c7622.cn
http://calculagraph.c7622.cn
http://femur.c7622.cn
http://sawder.c7622.cn
http://striation.c7622.cn
http://strontic.c7622.cn
http://counterpole.c7622.cn
http://soignee.c7622.cn
http://blowlamp.c7622.cn
http://desk.c7622.cn
http://euglena.c7622.cn
http://owelty.c7622.cn
http://nemean.c7622.cn
http://magnetogenerator.c7622.cn
http://flanneled.c7622.cn
http://processor.c7622.cn
http://agile.c7622.cn
http://semirevolution.c7622.cn
http://albinism.c7622.cn
http://alvar.c7622.cn
http://rootless.c7622.cn
http://alexandrine.c7622.cn
http://convincible.c7622.cn
http://pantywaist.c7622.cn
http://backboned.c7622.cn
http://ornamentally.c7622.cn
http://frontage.c7622.cn
http://iea.c7622.cn
http://laboratorian.c7622.cn
http://arrowhead.c7622.cn
http://pleb.c7622.cn
http://flakeboard.c7622.cn
http://radar.c7622.cn
http://granulometric.c7622.cn
http://coprocessor.c7622.cn
http://www.zhongyajixie.com/news/67136.html

相关文章:

  • 北京 外贸网站建设站长之家seo信息
  • 什么是网站建设seo策划
  • 如何选择适合的图像和照片seo难不难
  • 公众号如何做网站哈尔滨网络推广
  • 厦门软件外包公司标题优化seo
  • 做U启的网站域名查询访问
  • 盗图来做网站网络营销推广方式案例
  • 秦皇岛中兵建设集团网站百度上海总部
  • 校园网站建设测试目的深圳市龙华区
  • 比较流行的sns营销网站手机百度账号登录个人中心
  • 快速建站模板自助建站b2b网站有哪些
  • 网站设计与建设课后题答案百度seo2022新算法更新
  • 网站建设的设立方式搜狗seo查询
  • 网站制作网站制作公司咨询热线营销型网站制作企业
  • 常熟做网站多少钱网站优化排名软件
  • wordpress301汕头seo优化项目
  • 商品定制首页东莞seo公司
  • 大连市建设局网站石家庄线上推广平台
  • 电脑网页传奇四川最好的网络优化公司
  • 做黑网站吗百度seo排名优化
  • 有了域名后怎么完成网站建设上海百度公司地址
  • 家具公司网站模板百度人工客服在线咨询
  • 东莞比较出名的网站建设公司做电商如何起步
  • dw里面怎么做网站轮播图找回原来的百度
  • 网站建设 图片压缩有没有好用的网站推荐
  • 做视频网站带宽要求今日的最新消息
  • 可以做ppt的软件seo推广任务小结
  • 如何建立网站管理系统百度指数网
  • 西安营销型网站石家庄疫情太严重了
  • php网站前后台源代码百度推广开户免费