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

网站建设游戏ppt模板下载网站推荐

网站建设游戏,ppt模板下载网站推荐,深圳网站备案拍照点,可以上传网站的免费空间1.概念 map中所有元素都是pair<key,value>&#xff0c;key 是map的键&#xff0c;value 是map的值 所有元素都会根据key自动排序 map/multimap属于关联式容器&#xff0c;底层结构是用二叉树实现。 map和multimap区别&#xff1a; map不允许容器中有重复key值元素 m…

1.概念

map中所有元素都是pair<key,value>,key 是map的键,value 是map的值

所有元素都会根据key自动排序

map/multimap属于关联式容器,底层结构是用二叉树实现。

map和multimap区别

  • map不允许容器中有重复key值元素

  • multimap允许容器中有重复key值元素

2.map构造和赋值

map<T1,T2> mp;

map(const map &mp);// 拷贝构造

map &operator=(const map &mp);

#include <iostream>
#include <map>using namespace std;void printMap(const map<int,int> &mp)
{for(map<int,int>::const_iterator it = mp.begin(); it != mp.end(); it++){cout << "key = " << it->first << " value = " << it->second << endl;}cout<<endl;
}void test(){map<int,int> m;m.insert(pair<int,int>(1,10));m.insert(pair<int,int>(2,20));m.insert(pair<int,int>(3,30));printMap(m);map<int,int>m2(m);// 拷贝构造printMap(m2);map<int,int>m3;m3 = m2;// 赋值printMap(m3);}int main()
{test();system("pause");return 0;
}

3.map大小和交换

#include <iostream>
#include <map>using namespace std;void printMap(map<int, int> &m){for (map<int, int>::iterator it = m.begin(); it != m.end(); it++){cout << "key = " << it->first << " value = " << it->second << endl;}cout<<endl;
}
void test(){map<int,int> m;m.insert(pair<int,int>(1,10));m.insert(pair<int,int>(2,20));m.insert(pair<int,int>(3,30));if (m.empty()){cout<<"map为空"<<endl;}else{cout<<"map不为空"<<endl;cout<<"map的大小为:"<<m.size()<<endl;}map<int,int>m2(m);map<int,int>m3;m3.insert(pair<int,int>(4,40));m3.insert(pair<int,int>(5,50));m3.insert(pair<int,int>(6,60));m3.swap(m2);printMap(m3);}int main()
{test();system("pause");return 0;
}

4.map插入和删除

insert(elem);

clear();

erase(pos);// 删除pos位置的元素,返回删除元素的下一个位置

erase(beg,end);// 删除beg到end之间的元素,左闭右开

erase(key);// 删除key对应的元素

#include <iostream>
#include <map>using namespace std;void printMap(const map<int,int> &m){for(map<int,int>::const_iterator it=m.begin();it!=m.end();it++){cout<<it->first<<" "<<it->second<<endl;}cout<<endl;
}void test(){map<int,int> m;m.insert(pair<int,int>(1,10));m.insert(make_pair(2,20));m.insert(map<int,int>::value_type(3,30));m[4]=40;printMap(m);//删除m.erase(m.begin());printMap(m);m.erase(3);printMap(m);//清空m.clear();m.erase(m.begin(),m.end());printMap(m);
}int main()
{test();system("pause");return 0;
}

5. map查找和统计

find(key);// 查找key对应的value,不存在返回end()

count(key);// 统计key出现的次数

#include <iostream>
#include <map>using namespace std;void printMap(map<int, int> &m)
{for (map<int, int>::iterator it = m.begin(); it != m.end(); it++){cout << "key = " << it->first << " value = " << it->second << endl;}cout<<endl;
}void test(){map<int, int>m; m.insert(pair<int, int>(1, 10));m.insert(pair<int, int>(2, 20));m.insert(pair<int, int>(3, 30));auto pos=m.find(3);// auto自动推导迭代器类型if(pos!=m.end()){cout<<"key = "<<pos->first<<" value = "<<pos->second<<endl;}else{cout<<"没有找到key = 3"<<endl;}int num=m.count(1);cout<<"key = 1 出现的次数 = "<<num<<endl;
}int main()
{test();system("pause");return 0;
}

 6. map容器排序

map容器默认排序规则为 按照key值进行 从小到大排序

#include <iostream>
#include <map>using namespace std;class MyCompare{public:bool operator()(int v1,int v2) const{return v1>v2;}
};void test(){map<int, int, MyCompare> m;m.insert(make_pair(1, 10));m.insert(make_pair(2, 20));m.insert(make_pair(3, 30));m.insert(make_pair(4, 40));m.insert(make_pair(5, 50));for (map<int, int,MyCompare>::const_iterator it = m.begin(); it != m.end(); it++){cout << "key = " << it->first << " value = " << it->second << endl;}
}int main()
{test();system("pause");return 0;
}


文章转载自:

http://4BTLG9E6.fsLxc.cn
http://horIXJ76.fsLxc.cn
http://B03eNGXm.fsLxc.cn
http://QPgoZSkv.fsLxc.cn
http://8K75tw5s.fsLxc.cn
http://jAvwuAAP.fsLxc.cn
http://nKld2zAG.fsLxc.cn
http://HkdZh5O7.fsLxc.cn
http://l5MvE6Or.fsLxc.cn
http://MlO6YrOn.fsLxc.cn
http://EBCcZln0.fsLxc.cn
http://7X8Fust4.fsLxc.cn
http://pu5QEJbW.fsLxc.cn
http://c9KCPZUs.fsLxc.cn
http://F3pxaxxP.fsLxc.cn
http://ZMWqCEJa.fsLxc.cn
http://saRwaNgo.fsLxc.cn
http://k6Ht2nDk.fsLxc.cn
http://7G8lxX9z.fsLxc.cn
http://LHQTHlzM.fsLxc.cn
http://fi3VEHOb.fsLxc.cn
http://gRC9K68F.fsLxc.cn
http://OnKACOTD.fsLxc.cn
http://xq1uKPPS.fsLxc.cn
http://4hsxXZtv.fsLxc.cn
http://YeZq1Fcv.fsLxc.cn
http://2r61VBSz.fsLxc.cn
http://XnKehomv.fsLxc.cn
http://bs6o3VcC.fsLxc.cn
http://qrLKzBcN.fsLxc.cn
http://www.dtcms.com/wzjs/690631.html

相关文章:

  • 月子会所网站建设方案网站服务器怎么选
  • 如何在空白服务器上搭建网站动漫设计专修学校
  • 做网站的公司需要哪些资质视频软件制作
  • 12316网站建设方案网站开发主流技术
  • 网站百度不收录盆景网站建设swot分析
  • 做网站的程序员wordpress同步简书
  • 韩国设计app网站有哪些成品网站货源1688免费推荐
  • 外贸开发网站开发网站优化费用怎么做会计分录
  • 长春网站建设5219做装修的网站怎么做好
  • 广东网站设计哪家好网络建设和维护
  • 做好的网站怎么链接武威做网站
  • 响应式网站建设的优势做网站先学什么
  • 汕头制作公司网站沈阳大型网站设计公司
  • 常州市城市建设集团有限公司网站电子商务网站的规划与建设论文
  • 做十个网站按文章标题相关wordpress
  • 广州3d网站开发花店网站建设论文
  • 制作网站题材深圳网站排名怎么做
  • html网站设计论文搭建个官网需要多少钱
  • 免费ps软件网站做网站很难吗
  • 个人姓名最多备案多少个网站变装chinacd wordpress
  • 比较好的做网站的公司景区门户网站建设的必要性
  • vuejs 可做网站吗小红书广告代理商
  • 哪个网站能免费做电子书封面广州网站开发服务
  • 网站设计中下拉列表怎么做杭州集团公司网站建设
  • 网站建设学什么WordPress邮件代发
  • 站长平台社区云服务器是虚拟技术吗
  • 网站后台 生成所有页面网站源码44444kt
  • 响应式网站的开发做博客网站
  • 如何用电脑做网站服务器吗广州网站优化运营
  • asp旅游网站模板下载新闻发布会的意义