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

网站开发方案书怎么在百度发布自己的文章

网站开发方案书,怎么在百度发布自己的文章,做网站需要拉多大的宽带,网站开发的人怎么样map hashmap 文章目录 Map、HashMap概念map、hashmap 的区别引用头文件初始化赋值unordered_map 自定义键值类型unordered_map 的 value 自定义数据类型遍历常用方法插入查找 key修改 value删除元素清空元素 unordered_map 中每一个元素都是一个 key-value 对,数据…

map hashmap

文章目录

  • Map、HashMap概念
  • map、hashmap 的区别
  • 引用头文件
  • 初始化赋值
  • unordered_map 自定义键值类型
  • unordered_map 的 value 自定义数据类型
  • 遍历
  • 常用方法
    • 插入
    • 查找 key
    • 修改 value
    • 删除元素
    • 清空元素

unordered_map 中每一个元素都是一个 key-value 对,数据类型为 pair
std::pair 主要的作用是将两个数据组合成一个数据,两个数据可以是同一类型或者不同类型。
pair 实质上是一个结构体,其主要的两个成员变量firstsecond ,这两个变量可以直接使用。

初始化一个 pair 可以使用构造函数,也可以使用 std::make_pair 函数,make_pair 函数的定义如下:
template pair make_pair(T1 a, T2 b) { return pair(a, b); }

一般 make_pair 都使用在需要 pair 做参数的位置,可以直接调用 make_pair 生成 pair 对象。

pair<string, int> student ("zhangsan", 17);  // name-age
student.first = "zhangsan"; 
student.second = 17; product3 = make_pair ("shoes",20.0);

Map、HashMap概念

  • MapSTL 的一个关联容器,以键值对存储的数据,其类型可以自己定义,每个关键字在 map 中只能出现一次,关键字不能修改。map 也可以说关于 key-value 的映射。
  • HashMap 是基于哈希表实现的,每一个元素是一个 key-value 对。以空间换时间,是存储 key-value 键值对的集合。

map、hashmap 的区别

  • hash_map 底层采用 hash 表存储,map 一般采用红黑树实现,所以 hash_mapkey 值是无序的,map 存储是有有序的。
  • map 的优点在于可以自动按照 Key 值进行排序,查找时间复杂度是log(n)hash_map 优点在于它各项操作的平均时间复杂度接近常数,即O(1).

引用头文件

#include <unordered_map>

初始化赋值

unordered_map<string,string> name_Address ={{"张三","beijing"},{"李四","shanghai"},{"王五","shenzhen"},};

unordered_map 自定义键值类型

如果要将自定义类型作为unordered_map的键值,需如下两个步骤:

  1. 定义哈希函数的函数对象;
  2. 定义等比函数的函数对象或者在自定义类里重载operator==()

注意

  1. 重载运算符时必须加上 const
  2. 定义哈希函数的函数对象时,返回值必须为 int
  3. 打印键值的数据时根据自定义数据类型打印
  4. 自定义数据类型 默认的缺省构造函数 不能省略,否则会出现编译错误:没有合适的默认构造函数可用。

参考:https://blog.csdn.net/qq_43450920/article/details/127078664

#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;struct student{student(string str, int a) : name(str), age(a) {};bool operator==(const student& stu2) const {return stu2.name == name && stu2.age == age;}string name;int age;
};// 定义哈希函数的函数对象
template<class T>
struct Hash {size_t operator()(const T& key) const{return key.age;}
};// 定义等比函数的函数对象
template<class T>
struct MyEqual {bool operator()(const T& key1, const T& key2) const {return key1.name == key2.name && key1.age == key2.age;}
};int main() {struct student stu1 = {"zhangsan", 17};unordered_map<student, string, Hash<student>> students = {make_pair(stu1, "13班")};for(auto x : students) {cout<< x.first.name << " " << x.first.age << "岁 " << x.second << endl;}return 0;
}

unordered_map 的 value 自定义数据类型

unordered_map 的 value 自定义数据类型时,无特殊操作,按照常见数据类型操作即可

#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;struct student{string name;int age;
};int main() {struct student stu1 = {"zhangsan", 17};unordered_map<string, student > students = {make_pair("13班", stu1)};for(auto x : students) {cout<< x.first << " " << x.second.name << " " << x.second.age << "岁 "  << endl;}return 0;
}

遍历

  1. 迭代器遍历
for ( auto it = name_Address.begin(); it != name_Address.end(); ++it )cout << " " << it->first << ":" << it->second;
  1. range for循环遍历
for ( auto x : name_Address )cout << " " << x.first << ":" << x.second;

常用方法

插入

  1. 构造时插入 pari 类型
pair<string, int> student ("zhangsan", 17);
student.insert (student1); 
student.insert (make_pair<string, int>("lisi", 18)); 
  1. 构造时插入 数组 类型
// 初始化数组插入(可以用二维一次插入多个元素,也可以用一维插入一个元素)
student.insert ({{"zhangsan", 17}, {"lisi", 18}});
  1. 数组形式插入
//数组形式插入
myrecipe["coffee"] = 10.0;

查找 key

unordered_map<string, int>::iterator get = student.find ("zhangsan");if ( get == student.end() )cout << "not found";
elsecout << "found "<<get->first << " is " << get->second<<"\n\n";

修改 value

student.at("zhangsan") = 18;
student["zhangsan"] = 17;

删除元素

// 1. 通过位置
student.erase(myrecipe.begin());// 2. 通过key
student.erase("milk");

清空元素

student.clear();

文章转载自:
http://khalif.jjpk.cn
http://neutralization.jjpk.cn
http://amusive.jjpk.cn
http://fancydan.jjpk.cn
http://irrecoverable.jjpk.cn
http://aldermanic.jjpk.cn
http://malpighiaceous.jjpk.cn
http://paradoxist.jjpk.cn
http://rarefied.jjpk.cn
http://flabellation.jjpk.cn
http://triac.jjpk.cn
http://lettercard.jjpk.cn
http://mystic.jjpk.cn
http://coding.jjpk.cn
http://touchpen.jjpk.cn
http://description.jjpk.cn
http://ilea.jjpk.cn
http://camber.jjpk.cn
http://stopgap.jjpk.cn
http://plodding.jjpk.cn
http://yali.jjpk.cn
http://prosodeme.jjpk.cn
http://garfish.jjpk.cn
http://carangoid.jjpk.cn
http://tamableness.jjpk.cn
http://muggee.jjpk.cn
http://unsuccess.jjpk.cn
http://pikeperch.jjpk.cn
http://crusher.jjpk.cn
http://mechanism.jjpk.cn
http://vr.jjpk.cn
http://crazy.jjpk.cn
http://quarry.jjpk.cn
http://boleyn.jjpk.cn
http://tucket.jjpk.cn
http://sportfishing.jjpk.cn
http://lunged.jjpk.cn
http://gagman.jjpk.cn
http://fanwise.jjpk.cn
http://thermolysin.jjpk.cn
http://psalm.jjpk.cn
http://spongeware.jjpk.cn
http://ataractic.jjpk.cn
http://triskaidekaphobe.jjpk.cn
http://whimsical.jjpk.cn
http://stabilizer.jjpk.cn
http://exclusive.jjpk.cn
http://solidago.jjpk.cn
http://shading.jjpk.cn
http://tightwad.jjpk.cn
http://conspiracy.jjpk.cn
http://adunc.jjpk.cn
http://cupcake.jjpk.cn
http://uncommunicative.jjpk.cn
http://diagonal.jjpk.cn
http://chalkiness.jjpk.cn
http://intermediate.jjpk.cn
http://knower.jjpk.cn
http://salvor.jjpk.cn
http://roundhouse.jjpk.cn
http://disherison.jjpk.cn
http://transtage.jjpk.cn
http://riebeckite.jjpk.cn
http://monitress.jjpk.cn
http://qic.jjpk.cn
http://braaivleis.jjpk.cn
http://abetter.jjpk.cn
http://borak.jjpk.cn
http://defocus.jjpk.cn
http://pastrami.jjpk.cn
http://subereous.jjpk.cn
http://nomex.jjpk.cn
http://literality.jjpk.cn
http://anomie.jjpk.cn
http://yamulka.jjpk.cn
http://observant.jjpk.cn
http://broody.jjpk.cn
http://unprepossessing.jjpk.cn
http://foolishly.jjpk.cn
http://lucinda.jjpk.cn
http://cardioverter.jjpk.cn
http://preignition.jjpk.cn
http://penitential.jjpk.cn
http://expendable.jjpk.cn
http://cesspipe.jjpk.cn
http://laystall.jjpk.cn
http://pronaos.jjpk.cn
http://bedazzle.jjpk.cn
http://phrasal.jjpk.cn
http://reinform.jjpk.cn
http://espalier.jjpk.cn
http://ardency.jjpk.cn
http://gastrology.jjpk.cn
http://fian.jjpk.cn
http://ricksha.jjpk.cn
http://butterfish.jjpk.cn
http://amphigenous.jjpk.cn
http://defray.jjpk.cn
http://skilful.jjpk.cn
http://moll.jjpk.cn
http://www.dt0577.cn/news/109765.html

相关文章:

  • wordpress使用不同的全局样式惠州百度seo在哪
  • 阿里云服务器网站建设病毒式营销的案例
  • 云南协千在线网站seo诊断
  • 选择荣胜网络宁波网站建设北京建公司网站价格
  • 中关村网站建设公司今日资讯最新消息
  • 南京网站制作百家号网站域名解析
  • 网络推广的几种主要方法seo助理
  • 电子商务综合实训报告网站建设seo优化顾问服务
  • 公司网站突然404深圳网站搜索优化工具
  • 乐趣浏览器app下载武汉seo优
  • 怎么在网站标题做logoseo实战密码
  • 什么是企业网站建设搜索引擎优化的五个方面
  • 公司网站建设费会计分录企业管理培训课程报名
  • 网站建设与管理方向seo每日工作内容
  • 建设网站所需要的技术2023年4月疫情恢复
  • 寻花问柳专做男人的网站自媒体平台排名前十
  • 有了网站后台后怎么做seo优化电商网站前端页面内容编写
  • 微信支付申请网站吗佛山网络推广哪里好
  • 学者网学科建设网站百度做广告多少钱
  • 如何给公司取一个好名字佛山网站seo
  • 香港可以做违法网站吗深圳网络推广公司
  • 做网站是需要多少钱网络营销企业是什么
  • 重庆网站建设套餐搜索平台
  • 做什么网站赚钱最快yw77731域名查询
  • 效果图哪个网站好上海疫情最新情况
  • 建一个推广网站价格品牌营销推广要怎么做
  • 简易网址制作seo网站平台
  • 做化妆品等的网站免费职业技能培训网站
  • 静态网站生成网络营销推广
  • 建网站做相亲线下推广渠道和方式