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

怎么免费做公司网站文山网站建设哪家好

怎么免费做公司网站,文山网站建设哪家好,做网站入什么会计科目,品牌网页设计1.Map和Set的简单介绍 Map和set没有多大区别#xff0c;它俩都是键值对容器#xff0c;即该结构中一般只包含两个成员key#xff0c;value#xff0c;key代表键值#xff0c;value表示与key对应的信息。并且这两个容器为树型结构的关联式容器#xff0c;这两种容器的共同…1.Map和Set的简单介绍 Map和set没有多大区别它俩都是键值对容器即该结构中一般只包含两个成员keyvaluekey代表键值value表示与key对应的信息。并且这两个容器为树型结构的关联式容器这两种容器的共同点是使用平衡搜索树(即红黑树)作为其底层结果容器中的元素是一个有序的序列。 Set的介绍  set是按照一定次序存储元素的容器。 在set中元素的value也标识它(value就是key类型为T)并且每个value必须是唯一的。set中的元素不能在容器中修改(元素总是const)但是可以从容器中插入或删除它们。在内部set中的元素总是按照其内部比较对象(类型比较)所指示的特定严格弱排序准则进行排序。set容器通过key访问单个元素的速度通常比unordered_set容器慢但它们允许根据顺序对子集进行直接迭代。set在底层是用二叉搜索树(红黑树)实现的。 注意 与map/multimap不同map/multimap中存储的是真正的键值对key, valueset中只放value但在底层实际存放的是由value, value构成的键值对。set中插入元素时只需要插入value即可不需要构造键值对。set中的元素不可以重复(因此可以使用set进行去重)。使用set的迭代器遍历set中的元素可以得到有序序列set中的元素默认按照小于来比较set中查找某个元素时间复杂度为$log_2 n$set中的元素不允许修改set中的底层使用二叉搜索树(红黑树)来实现 Map的介绍 map是关联容器它按照特定的次序(按照key来比较)存储由键值key和值value组合而成的元素。在map中键值key通常用于排序和惟一地标识元素而值value中存储与此键值key关联的内容。键值key和值value的类型可能不同并且在map的内部key与value通过成员类型value_type绑定在一起为其取别名称为pair:typedef pairconst key, T value_type;在内部map中的元素总是按照键值key进行比较排序的。map中通过键值访问单个元素的速度通常比unordered_map容器慢但map允许根据顺序对元素进行直接迭代(即对map中的元素进行迭代时可以得到一个有序的序列)。map支持下标访问符即在[]中放入key就可以找到与key对应的value。 map通常被实现为二叉搜索树(更准确的说平衡二叉搜索树(红黑树))。   2.Map和Set的实现 由于Map和Set的底层都为红黑树所以Map和Set的实现通过对红黑树的封装来实现Set为一个参数Map为两个参数所以通过改变模板来实现Map和Set的同时封装。 Set的简单封装 namespace sss {templateclass Kclass Set{struct SetKeyofT{const K operator()(const K date){return date;}}; public:typedef typename RedBlackTreeK, K, SetKeyofT::iterator iterator;iterator begin(){return _S.begin();}iterator end(){return _S.end();}pairiterator, bool Insert(const K date){return _S.insert(date);}private:RedBlackTreeK, K, SetKeyofT _S;};//测试用例/*void text_set(){string str[] { 苹果, 西瓜, 苹果, 西瓜, 苹果, 苹果, 西瓜, 苹果, 香蕉, 苹果, 香蕉 };Setstring hash;for (auto sh : str){hash.Insert(sh);}auto it hash.begin();while (it ! hash.end()){cout *it endl;it;}}*/} Map的简单封装 namespace sss {templateclass K,class V class Map{public:struct MapKeyofT{const K operator()(const pairK, V date){return date.first;}};typedef typename RedBlackTreeK, pairK, V, MapKeyofT::iterator iterator;//t//ypedef RedBlackTreeK, pairK, V, MapKeyofT RedBlackTree;iterator begin() {return _T.begin();}iterator end(){return _T.end();}pairiterator, bool Insert(const pairK,V date){return _T.insert(date);}V operator[](const K key){pairiterator, bool ret Insert(make_pair(key, V()));return ret.first-second;}private:RedBlackTreeK,pairK,V, MapKeyofT _T;};//测试用例//void text_map()//{// Mapint, int hash1;// hash1.Insert(make_pair(1,1));// couthash1[1];// Mapstring, int hash2;// string str[] { 苹果, 西瓜, 苹果, 西瓜, 苹果, 苹果, 西瓜, 苹果, 香蕉, 苹果, 香蕉 };// for (auto sh:str)// {// hash2[sh];// }// Mapstring, int::iterator it hash2.begin();// while (it ! hash2.end())// {// cout it-first : it-second endl;// it;// }// for (auto kv : hash2)// {// cout kv.first : kv.second endl;// }// //hash1 hash2;// //} } 底层实现 namespace sss {enum Color{red,black};templateclass Tstruct RedBlackTreeNode{RedBlackTreeNodeT* _left;RedBlackTreeNodeT* _right;RedBlackTreeNodeT* _parent;//pairK, V _date;T _date;Color _col;RedBlackTreeNode(const T dateT()):_left(nullptr),_right(nullptr),_parent(nullptr),_date(date)//, _col(black){}};templateclass T, class Ref, class Ptrstruct __RBTreeIterator{typedef RedBlackTreeNodeT Node;typedef __RBTreeIteratorT, Ref, Ptr Self;Node* _node;__RBTreeIterator(Node* node):_node(node){}Ref operator*(){return _node-_date;}Ptr operator-(){return _node-_date;}bool operator!(const Self _t){return _node ! _t._node;}bool operator(const Self _t){return _node _t._node;}Self* operator(){if (_node-_right){Node* cur _node;cur cur-_right;while (cur-_left){cur cur-_left;}_nodecur;}else{Node* parent _node-_parent;Node* cur _node;while (parent cur parent-_right){cur cur-_parent;parent parent-_parent;}_nodeparent;}return this;}Self* operator--(){if (_node-_left){Node* cur _node;cur cur-_left;while (cur-_right){cur cur-_right;}_nodecur;}else{Node* parent _node-_parent;Node* cur _node;while (parent cur parent-left){parent parent-_parent;cur parent;}_node parent;}return this;}};templateclass K, class T, class KeyofTclass RedBlackTree{typedef RedBlackTreeNodeT Node;public: typedef __RBTreeIteratorT, T, T* iterator;iterator begin(){Node* left _root;while (left left-_left){left left-_left;}return iterator(left);}iterator end(){return iterator(nullptr);}//插入pairiterator,bool insert(const T date){KeyofT _com;if (_root nullptr){_root new Node(date);_root-_col black;return make_pair(iterator(_root), true);}Node* parent nullptr;Node* cur _root;while (cur){if (_com(cur-_date) _com(date)){parent cur;cur cur-_right;}else if (_com(cur-_date) _com(date)){parent cur;cur cur-_left;}else{return make_pair(iterator(cur), false);}}cur new Node(date);cur-_col red;if (_com(parent-_date) _com(date)){parent-_right cur;}else {parent-_left cur;}cur-_parent parent;//Node* uncleparent-_parent-while(parent parent-_col red){Node* grandfater parent-_parent;assert(grandfater);assert(grandfater-_colblack);if (parent grandfater-_left){Node* uncle grandfater-_right;// 情况一 : uncle存在且为红变色继续往上处理if (uncle uncle-_col red){parent-_col uncle-_col black;grandfater-_col red;// 继续往上处理cur grandfater;parent cur-_parent;}// 情况二三uncle不存在 存在且为黑else{// 情况二右单旋变色// g // p u// cif (cur parent-_left){RotateR(grandfater);parent-_col black;grandfater-_col red;}else{// 情况三左右单旋变色// g // p u// cRotateL(parent);RotateR(grandfater);cur-_col black;grandfater-_col red;}break;}}else{Node* uncle grandfater-_left;// 情况一if (uncle uncle-_col red){parent-_col uncle-_col black;grandfater-_col red;// 继续往上处理cur grandfater;parent cur-_parent;}else{// 情况二左单旋变色// g // u p// cif (cur parent-_right){RotateL(grandfater);parent-_col black;grandfater-_col red;}else{// 情况三右左单旋变色// g // u p// cRotateR(parent);RotateL(grandfater);cur-_col black;grandfater-_col red;}break;}}}_root-_col black;return make_pair(iterator(cur), true);}void Inorder(){_Inorder(_root);}private://右旋void RotateR(Node* parent){Node* subl parent-_left;Node* sublr subl-_right;Node* prev parent-_parent;parent-_left sublr;if (sublr)sublr-_parent parent;parent-_parent subl;subl-_right parent;if (_root parent){_root subl;subl-_parent nullptr;}else{if (prev-_left parent){subl-_parent prev;prev-_left subl;}else{subl-_parent prev;prev-_right subl;}}}//左旋void RotateL(Node* parent){Node* subr parent-_right;Node* subrl subr-_left;Node* prev parent-_parent;parent-_right subrl;if (subrl)subrl-_parent parent;subr-_left parent;parent-_parent subr;if (_root parent){_root subr;subr-_parent nullptr;}else{if (prev-_left parent){subr-_parent prev;prev-_left subr;}else{subr-_parent prev;prev-_right subr;}}}//遍历void _Inorder(Node* _root){if (_root nullptr)return;_Inorder(_root-_left);cout _root-_date.first _root-_date.second endl;_Inorder(_root-_right);}private:Node* _root nullptr;};} 完整代码 //在不同平台下需加不同头文件 #pragma once using namespace std; #include iostream #include assert.h #include RedBlackTree.h #include stringnamespace sss {templateclass Kclass Set{struct SetKeyofT{const K operator()(const K date){return date;}}; public:typedef typename RedBlackTreeK, K, SetKeyofT::iterator iterator;iterator begin(){return _S.begin();}iterator end(){return _S.end();}pairiterator, bool Insert(const K date){return _S.insert(date);}private:RedBlackTreeK, K, SetKeyofT _S;};//测试用例/*void text_set(){string str[] { 苹果, 西瓜, 苹果, 西瓜, 苹果, 苹果, 西瓜, 苹果, 香蕉, 苹果, 香蕉 };Setstring hash;for (auto sh : str){hash.Insert(sh);}auto it hash.begin();while (it ! hash.end()){cout *it endl;it;}}*/}namespace sss {templateclass K,class V class Map{public:struct MapKeyofT{const K operator()(const pairK, V date){return date.first;}};typedef typename RedBlackTreeK, pairK, V, MapKeyofT::iterator iterator;//t//ypedef RedBlackTreeK, pairK, V, MapKeyofT RedBlackTree;iterator begin() {return _T.begin();}iterator end(){return _T.end();}pairiterator, bool Insert(const pairK,V date){return _T.insert(date);}V operator[](const K key){pairiterator, bool ret Insert(make_pair(key, V()));return ret.first-second;}private:RedBlackTreeK,pairK,V, MapKeyofT _T;};//测试用例//void text_map()//{// Mapint, int hash1;// hash1.Insert(make_pair(1,1));// couthash1[1];// Mapstring, int hash2;// string str[] { 苹果, 西瓜, 苹果, 西瓜, 苹果, 苹果, 西瓜, 苹果, 香蕉, 苹果, 香蕉 };// for (auto sh:str)// {// hash2[sh];// }// Mapstring, int::iterator it hash2.begin();// while (it ! hash2.end())// {// cout it-first : it-second endl;// it;// }// for (auto kv : hash2)// {// cout kv.first : kv.second endl;// }// //hash1 hash2;// //} }namespace sss {enum Color{red,black};templateclass Tstruct RedBlackTreeNode{RedBlackTreeNodeT* _left;RedBlackTreeNodeT* _right;RedBlackTreeNodeT* _parent;//pairK, V _date;T _date;Color _col;RedBlackTreeNode(const T dateT()):_left(nullptr),_right(nullptr),_parent(nullptr),_date(date)//, _col(black){}};templateclass T, class Ref, class Ptrstruct __RBTreeIterator{typedef RedBlackTreeNodeT Node;typedef __RBTreeIteratorT, Ref, Ptr Self;Node* _node;__RBTreeIterator(Node* node):_node(node){}Ref operator*(){return _node-_date;}Ptr operator-(){return _node-_date;}bool operator!(const Self _t){return _node ! _t._node;}bool operator(const Self _t){return _node _t._node;}Self* operator(){if (_node-_right){Node* cur _node;cur cur-_right;while (cur-_left){cur cur-_left;}_nodecur;}else{Node* parent _node-_parent;Node* cur _node;while (parent cur parent-_right){cur cur-_parent;parent parent-_parent;}_nodeparent;}return this;}Self* operator--(){if (_node-_left){Node* cur _node;cur cur-_left;while (cur-_right){cur cur-_right;}_nodecur;}else{Node* parent _node-_parent;Node* cur _node;while (parent cur parent-left){parent parent-_parent;cur parent;}_node parent;}return this;}};templateclass K, class T, class KeyofTclass RedBlackTree{typedef RedBlackTreeNodeT Node;public: typedef __RBTreeIteratorT, T, T* iterator;iterator begin(){Node* left _root;while (left left-_left){left left-_left;}return iterator(left);}iterator end(){return iterator(nullptr);}//插入pairiterator,bool insert(const T date){KeyofT _com;if (_root nullptr){_root new Node(date);_root-_col black;return make_pair(iterator(_root), true);}Node* parent nullptr;Node* cur _root;while (cur){if (_com(cur-_date) _com(date)){parent cur;cur cur-_right;}else if (_com(cur-_date) _com(date)){parent cur;cur cur-_left;}else{return make_pair(iterator(cur), false);}}cur new Node(date);cur-_col red;if (_com(parent-_date) _com(date)){parent-_right cur;}else {parent-_left cur;}cur-_parent parent;//Node* uncleparent-_parent-while(parent parent-_col red){Node* grandfater parent-_parent;assert(grandfater);assert(grandfater-_colblack);if (parent grandfater-_left){Node* uncle grandfater-_right;// 情况一 : uncle存在且为红变色继续往上处理if (uncle uncle-_col red){parent-_col uncle-_col black;grandfater-_col red;// 继续往上处理cur grandfater;parent cur-_parent;}// 情况二三uncle不存在 存在且为黑else{// 情况二右单旋变色// g // p u// cif (cur parent-_left){RotateR(grandfater);parent-_col black;grandfater-_col red;}else{// 情况三左右单旋变色// g // p u// cRotateL(parent);RotateR(grandfater);cur-_col black;grandfater-_col red;}break;}}else{Node* uncle grandfater-_left;// 情况一if (uncle uncle-_col red){parent-_col uncle-_col black;grandfater-_col red;// 继续往上处理cur grandfater;parent cur-_parent;}else{// 情况二左单旋变色// g // u p// cif (cur parent-_right){RotateL(grandfater);parent-_col black;grandfater-_col red;}else{// 情况三右左单旋变色// g // u p// cRotateR(parent);RotateL(grandfater);cur-_col black;grandfater-_col red;}break;}}}_root-_col black;return make_pair(iterator(cur), true);}void Inorder(){_Inorder(_root);}private://右旋void RotateR(Node* parent){Node* subl parent-_left;Node* sublr subl-_right;Node* prev parent-_parent;parent-_left sublr;if (sublr)sublr-_parent parent;parent-_parent subl;subl-_right parent;if (_root parent){_root subl;subl-_parent nullptr;}else{if (prev-_left parent){subl-_parent prev;prev-_left subl;}else{subl-_parent prev;prev-_right subl;}}}//左旋void RotateL(Node* parent){Node* subr parent-_right;Node* subrl subr-_left;Node* prev parent-_parent;parent-_right subrl;if (subrl)subrl-_parent parent;subr-_left parent;parent-_parent subr;if (_root parent){_root subr;subr-_parent nullptr;}else{if (prev-_left parent){subr-_parent prev;prev-_left subr;}else{subr-_parent prev;prev-_right subr;}}}//遍历void _Inorder(Node* _root){if (_root nullptr)return;_Inorder(_root-_left);cout _root-_date.first _root-_date.second endl;_Inorder(_root-_right);}private:Node* _root nullptr;};}
http://www.zqtcl.cn/news/225826/

相关文章:

  • pc主页网站建设专业公司网站建设服务公司
  • js 取网站域名做服装团购有哪些网站有哪些
  • ysl网站设计论文网站快照回档
  • 网站建设成本计划汕头网站开发服务
  • 云朵课堂网站开发怎么收费wordpress安装完不显示
  • 网站建设进什么分录wordpress5.0 安装
  • 网站建设丷金手指专业十五户县规划建设和住房保障局网站
  • 普通门户网站开发价格怎么查公司信息
  • 广告传媒公司网站怎么做高品质的网站开发公司
  • 建设品牌型网站制作一起做玩具网站
  • 中山品牌网站设计自建站怎么做
  • 最牛免费网站建设wordpress 相册功能
  • 网站开发是培训网站开发毕业设计评审表
  • 网站对网友发帖隐私做处理网站怎么上传模板
  • 网站建设大神级公司网站 百度地图
  • 网站营销定义高端网站建设免费分析
  • 韩国网站建站html5修改器下载
  • 网站做联盟广告能赚钱吗如何制作微信小程序教程
  • 免费网页代理浏览器1广州seo效果
  • 网站开发所需基础知识学网络营销有前途吗
  • php网站怎么做集群wordpress添加产品图
  • 公司怎么建立网站吗聊城高端网站建设
  • 女生做网站编辑wordpress 办公主题
  • 接单做网站的从什么网站建网站好
  • 服务器如何发布网站正能量不良网站进入窗口免费阅读
  • 深圳个性化建网站服务商百度秒收录神器
  • 金华做公司网站wordpress会员可见插件
  • 访问自己做的网站河南百度推广公司
  • Wordpress+仿站+工具建筑材料采购网站
  • 汕头免费建设网站制作阆中市网站建设