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

建设工程消防验收查询网站公司名字变了网站备案

建设工程消防验收查询网站,公司名字变了网站备案,网络公司 网站建设 小程序,山西建设执业资格注册管理中心网站cMap是STL的一个关联容器#xff0c;它提供一对一#xff08;其中第一个可以称为关键字#xff0c;每个关键字只能在map中出现一次#xff0c;第二个可能称为该关键字的值#xff09;的数据处理能力#xff0c;由于这个特性#xff0c;它完成有可能在我们处理一对一数据…cMap是STL的一个关联容器它提供一对一其中第一个可以称为关键字每个关键字只能在map中出现一次第二个可能称为该关键字的值的数据处理能力由于这个特性它完成有可能在我们处理一对一数据的时候在编程上提供快速通道。这里说下map内部数据的组织map内部自建一颗红黑树(一种非严格意义上的平衡二叉树)这颗树具有对数据自动排序的功能所以在map内部所有的数据都是有序的后边我们会见识到有序的好处。1. map的构造函数mapint, string maphai;mapchar,int maphai;mapstring,char mapstring;mapstring,int mapstring;mapint ,charmapint;mapchar,stringmapchar;2. 数据的插入在构造map容器后我们就可以往里面插入数据了。这里讲三种插入数据的方法第一种用insert函数插入pair数据#include map#include string#include iostreamUsing namespace std;Int main(){Mapint, string mapStudent;mapStudent.insert(pairint, string(1, “student_one”));mapStudent.insert(pairint, string(2, “student_two”));mapStudent.insert(pairint, string(3, “student_three”));mapint, string::iterator iter;for(iter mapStudent.begin(); iter ! mapStudent.end(); iter){Coutiter-first” ”iter-secondend;}}第二种用insert函数插入value_type数据下面举例说明#include map#include string#include iostreamUsing namespace std;Int main(){Mapint, string mapStudent;mapStudent.insert(mapint, string::value_type (1, “student_one”));mapStudent.insert(mapint, string::value_type (2, “student_two”));mapStudent.insert(mapint, string::value_type (3, “student_three”));mapint, string::iterator iter;for(iter mapStudent.begin(); iter ! mapStudent.end(); iter){Coutiter-first” ”iter-secondend;}}第三种用数组方式插入数据下面举例说明#include map#include string#include iostreamUsing namespace std;Int main(){Mapint, string mapStudent;mapStudent[1] “student_one”;mapStudent[2] “student_two”;mapStudent[3] “student_three”;mapint, string::iterator iter;for(iter mapStudent.begin(); iter ! mapStudent.end(); iter){Coutiter-first” ”iter-secondend;}}以上三种用法虽然都可以实现数据的插入但是它们是有区别的当然了第一种和第二种在效果上是完成一样的用insert函数插入数据在数据的插入上涉及到集合的唯一性这个概念即当map中有这个关键字时insert操作是插入数据不了的但是用数组方式就不同了它可以覆盖以前该关键字对应的值用程序说明mapStudent.insert(mapint, string::value_type (1, “student_one”));mapStudent.insert(mapint, string::value_type (1, “student_two”));上面这两条语句执行后map中1这个关键字对应的值是“student_one”第二条语句并没有生效那么这就涉及到我们怎么知道insert语句是否插入成功的问题了可以用pair来获得是否插入成功程序如下Pairmapint, string::iterator, bool Insert_Pair;Insert_Pair mapStudent.insert(mapint, string::value_type (1, “student_one”));我们通过pair的第二个变量来知道是否插入成功它的第一个变量返回的是一个map的迭代器如果插入成功的话Insert_Pair.second应该是true的否则为false。下面给出完成代码演示插入成功与否问题#include map#include string#include iostreamUsing namespace std;Int main(){Mapint, string mapStudent;Pairmapint, string::iterator, bool Insert_Pair;Insert_Pair mapStudent.insert(pairint, string(1, “student_one”));If(Insert_Pair.second true){Cout”Insert Successfully”endl;}Else{Cout”Insert Failure”endl;}Insert_Pair mapStudent.insert(pairint, string(1, “student_two”));If(Insert_Pair.second true){Cout”Insert Successfully”endl;}Else{Cout”Insert Failure”endl;}mapint, string::iterator iter;for(iter mapStudent.begin(); iter ! mapStudent.end(); iter){Coutiter-first” ”iter-secondend;}}大家可以用如下程序看下用数组插入在数据覆盖上的效果#include map#include string#include iostreamUsing namespace std;Int main(){Mapint, string mapStudent;mapStudent[1] “student_one”;mapStudent[1] “student_two”;mapStudent[2] “student_three”;mapint, string::iterator iter;for(iter mapStudent.begin(); iter ! mapStudent.end(); iter){Coutiter-first” ”iter-secondend;}}3. map的大小在往map里面插入了数据我们怎么知道当前已经插入了多少数据呢可以用size函数用法如下Int nSize mapStudent.size();4. 数据的遍历这里也提供三种方法对map进行遍历第一种应用前向迭代器上面举例程序中到处都是了略过不表第二种应用反相迭代器下面举例说明要体会效果请自个动手运行程序#include map#include string#include iostreamUsing namespace std;Int main(){Mapint, string mapStudent;mapStudent.insert(pairint, string(1, “student_one”));mapStudent.insert(pairint, string(2, “student_two”));mapStudent.insert(pairint, string(3, “student_three”));mapint, string::reverse_iterator iter;for(iter mapStudent.rbegin(); iter ! mapStudent.rend(); iter){Coutiter-first” ”iter-secondend;}}第三种用数组方式程序说明如下#include map#include string#include iostreamUsing namespace std;Int main(){Mapint, string mapStudent;mapStudent.insert(pairint, string(1, “student_one”));mapStudent.insert(pairint, string(2, “student_two”));mapStudent.insert(pairint, string(3, “student_three”));int nSize mapStudent.size()//此处有误应该是 for(int nIndex 1; nIndex nSize; nIndex) //by rainfishfor(int nIndex 0; nIndex nSize; nIndex){CoutmapStudent[nIndex]end;}}5. 数据的查找包括判定这个关键字是否在map中出现在这里我们将体会map在数据插入时保证有序的好处。要判定一个数据关键字是否在map中出现的方法比较多这里标题虽然是数据的查找在这里将穿插着大量的map基本用法。这里给出三种数据查找方法第一种用count函数来判定关键字是否出现其缺点是无法定位数据出现位置,由于map的特性一对一的映射关系就决定了count函数的返回值只有两个要么是0要么是1出现的情况当然是返回1了第二种用find函数来定位数据出现位置它返回的一个迭代器当数据出现时它返回数据所在位置的迭代器如果map中没有要查找的数据它返回的迭代器等于end函数返回的迭代器程序说明#include map#include string#include iostreamUsing namespace std;Int main(){Mapint, string mapStudent;mapStudent.insert(pairint, string(1, “student_one”));mapStudent.insert(pairint, string(2, “student_two”));mapStudent.insert(pairint, string(3, “student_three”));mapint, string::iterator iter;iter mapStudent.find(1);if(iter ! mapStudent.end()){Cout”Find, the value is ”iter-secondendl;}Else{Cout”Do not Find”endl;}}第三种这个方法用来判定数据是否出现是显得笨了点但是我打算在这里讲解Lower_bound函数用法这个函数用来返回要查找关键字的下界(是一个迭代器)Upper_bound函数用法这个函数用来返回要查找关键字的上界(是一个迭代器)例如map中已经插入了1234的话如果lower_bound(2)的话返回的2而upper-bound2的话返回的就是3Equal_range函数返回一个pairpair里面第一个变量是Lower_bound返回的迭代器pair里面第二个迭代器是Upper_bound返回的迭代器如果这两个迭代器相等的话则说明map中不出现这个关键字程序说明#include map#include string#include iostreamUsing namespace std;Int main(){Mapint, string mapStudent;mapStudent[1] “student_one”;mapStudent[3] “student_three”;mapStudent[5] “student_five”;mapint, string::iterator iter;iter mapStudent.lower_bound(2);{//返回的是下界3的迭代器Coutiter-secondendl;}iter mapStudent.lower_bound(3);{//返回的是下界3的迭代器Coutiter-secondendl;}iter mapStudent.upper_bound(2);{//返回的是上界3的迭代器Coutiter-secondendl;}iter mapStudent.upper_bound(3);{//返回的是上界5的迭代器Coutiter-secondendl;}Pairmapint, string::iterator, mapint, string::iterator mapPair;mapPair mapStudent.equal_range(2);if(mapPair.first mapPair.second){cout”Do not Find”endl;}Else{Cout”Find”endl;}mapPair mapStudent.equal_range(3);if(mapPair.first mapPair.second){cout”Do not Find”endl;}Else{Cout”Find”endl;}}6. 数据的清空与判空清空map中的数据可以用clear()函数判定map中是否有数据可以用empty()函数它返回true则说明是空map7. 数据的删除这里要用到erase函数它有三个重载了的函数下面在例子中详细说明它们的用法#include map#include string#include iostreamUsing namespace std;Int main(){Mapint, string mapStudent;mapStudent.insert(pairint, string(1, “student_one”));mapStudent.insert(pairint, string(2, “student_two”));mapStudent.insert(pairint, string(3, “student_three”));//如果你要演示输出效果请选择以下的一种你看到的效果会比较好//如果要删除1,用迭代器删除mapint, string::iterator iter;iter mapStudent.find(1);mapStudent.erase(iter);//如果要删除1用关键字删除Int n mapStudent.erase(1);//如果删除了会返回1否则返回0//用迭代器成片的删除//一下代码把整个map清空mapStudent.earse(mapStudent.begin(), mapStudent.end());//成片删除要注意的是也是STL的特性删除区间是一个前闭后开的集合//自个加上遍历代码打印输出吧}8. 其他一些函数用法这里有swap,key_comp,value_comp,get_allocator等函数感觉到这些函数在编程用的不是很多略过不表有兴趣的话可以自个研究9. 排序这里要讲的是一点比较高深的用法了,排序问题STL中默认是采用小于号来排序的以上代码在排序上是不存在任何问题的因为上面的关键字是int型它本身支持小于号运算在一些特殊情况比如关键字是一个结构体涉及到排序就会出现问题因为它没有小于号操作insert等函数在编译的时候过不去下面给出两个方法解决这个问题第一种小于号重载程序举例#include map#include stringUsing namespace std;Typedef struct tagStudentInfo{Int nID;String strName;}StudentInfo, *PStudentInfo; //学生信息Int main(){int nSize;//用学生信息映射分数mapStudentInfo, intmapStudent;mapStudentInfo, int::iterator iter;StudentInfo studentInfo;studentInfo.nID 1;studentInfo.strName “student_one”;mapStudent.insert(pairStudentInfo, int(studentInfo, 90));studentInfo.nID 2;studentInfo.strName “student_two”;mapStudent.insert(pairStudentInfo, int(studentInfo, 80));for (itermapStudent.begin(); iter!mapStudent.end(); iter)coutiter-first.nIDendliter-first.strNameendliter-secondendl;}以上程序是无法编译通过的只要重载小于号就OK了如下Typedef struct tagStudentInfo{Int nID;String strName;Bool operator (tagStudentInfo const _A) const{//这个函数指定排序策略按nID排序如果nID相等的话按strName排序If(nID _A.nID) return true;If(nID _A.nID) return strName.compare(_A.strName) 0;Return false;}}StudentInfo, *PStudentInfo; //学生信息第二种仿函数的应用这个时候结构体中没有直接的小于号重载程序说明#include map#include stringUsing namespace std;Typedef struct tagStudentInfo{Int nID;String strName;}StudentInfo, *PStudentInfo; //学生信息Classs sort{Public:Bool operator() (StudentInfo const _A, StudentInfo const _B) const{If(_A.nID _B.nID) return true;If(_A.nID _B.nID) return _A.strName.compare(_B.strName) 0;Return false;}};Int main(){//用学生信息映射分数MapStudentInfo, int, sortmapStudent;StudentInfo studentInfo;studentInfo.nID 1;studentInfo.strName “student_one”;mapStudent.insert(pairStudentInfo, int(studentInfo, 90));studentInfo.nID 2;studentInfo.strName “student_two”;mapStudent.insert(pairStudentInfo, int(studentInfo, 80));}
http://www.pierceye.com/news/765574/

相关文章:

  • 如何做旅游小视频网站比较好的外贸公司
  • 图书馆建设投稿网站使用 ahrefs 进行 seo 分析
  • 校园网站建设 德育免费换ip软件
  • 排行网站模板凡科代理千万不要做
  • 贵州省冶金建设有限公司网站网站好玩新功能
  • 怎么让客户做网站惠州关键词排名提升
  • 创建公司网站需要什么国外的智慧城市建设网站
  • 阿里云服务器做网站django高清无版权网站
  • 网页制作与网站制作wordpress二次元风格
  • 贵州省城乡建设局网签网站工业设计网站有那些
  • 网站 电信已备案 联通泗阳做网站设计
  • 胶州做淘宝的网站龙南黄页全部电话
  • 可以看网站的手机浏览器藁城住房和城乡建设局网站
  • 关于网站制作的指标哪家公司网站做的比较好
  • 网站开发一般多少钱规划设计公司毛利
  • .net 网站地图高端网站建设 n磐石网络
  • 商丘网站建设价格无锡网站建设制作公司
  • 做装饰材料的网站dede英文网站
  • 长沙招聘网站哪个最好网站登录页面html模板
  • 网页创建网站做商城网站报价
  • 网网站建设公司网络整合营销
  • 广州本地门户网站wordpress视频格式
  • 做网站如何购买服务器自己做的网站注册用户无法收到激活邮箱的邮件
  • 商城网站系统建设中信建设有限责任公司 吴方旭
  • 辽阳市建设行业培训中心网站蒙文门户网站建设
  • 凡科建站官网入口wordpress个性首页
  • 上海信息技术做网站不连接wordpress安装
  • 高端网站开发培训免费企业黄页查询网站
  • 最新的网站开发技术全国新冠新增最新消息
  • 试玩app推广网站建设广州网站维护制作