湖北神润建设工程网站,网站维护 公司简介,市场营销推广方案模板,汕头网站设计怎么做我们这章所学的map / set 系列和后续会讲解的 unordered_map / unordered 系列都属于是关联式容器。 那么什么是关联式容器#xff1f; 关联式容器用于存储 键值对 (key, value)#xff0c;与序列式容器不同#xff0c;关联式容器的元素通过 键 来查找、插入和删除。…我们这章所学的map / set 系列和后续会讲解的 unordered_map / unordered 系列都属于是关联式容器。那么什么是关联式容器 关联式容器用于存储键值对(key, value)与序列式容器不同关联式容器的元素通过键来查找、插入和删除。它们通常采用平衡二叉搜索树如map、set的红黑树实现或哈希表如unordered_map、unordered_set来实现因此在查找、插入和删除等操作时比序列式容器更高效时间复杂度通常为对数级别O(log n)或O(1)。常见的关联式容器包括map、set、multimap、multiset以及使用哈希表实现的unordered_map和unordered_set。 它的底层逻辑结构是非线性的两个位置的储存值之间是紧密关联的如果交换他们的值就会破坏其储存结构。二、键值对pair1.认识键值对Key-Value Pair是指由键Key和值Value组成的元素结构。键是唯一标识元素的标志而值则是与该键相关联的数据。常见的关联式容器如map、unordered_map存储的就是这种键值对结构。键Key用于唯一标识元素。每个键在容器中是唯一的不会重复。值Value与键相关联的数据键对应的值可以是任何数据类型。例如mapint, string存储的键值对可能是{1, apple}其中1是键apple是与该键相关的值。通过键我们可以快速查找到对应的值。简而言之键值对是容器中元素的基本组成单元键用来查找和访问数据值存储实际的数据内容。pair的基本结构代码语言javascriptAI代码解释template class T1, class T2 struct pair { typedef T1 first_type; // 定义第一个类型的别名 typedef T2 second_type; // 定义第二个类型的别名 T1 first; // 第一个元素 T2 second; // 第二个元素 // 默认构造函数使用默认构造函数初始化 first 和 second pair() : first(T1()), second(T2()) {} // 带参数的构造函数用给定的值初始化 first 和 second pair(const T1 a, const T2 b) : first(a), second(b) {} };2.构造函数在这里插入图片描述默认构造代码语言javascriptAI代码解释// 默认构造函数初始化 first 和 second 成员为各自类型的默认值 pair(); // 实现通过默认构造函数初始化 first 和 second 成员 pair() : first(T1()), second(T2()) {} // T1() 和 T2() 是类型 T1 和 T2 的默认构造函数 // 它们会被调用来初始化 first 和 second。 // 如果 T1 或 T2 是类类型默认构造函数会被调用。 // 如果是基本类型如 int则 first 和 second 会被初始化为 0。拷贝构造代码语言javascriptAI代码解释// 拷贝构造函数通过拷贝另一个 pair 对象来初始化当前对象 templateclass U, class V pair(const pairU, V pr); // 实现用另一个 pairU, V 对象的 first 和 second 成员来初始化当前 pair 对象 pair(const pairU, V pr) : first(pr.first), second(pr.second) {} // pr.first 和 pr.second 分别是传入的 pair 对象的 first 和 second 成员。 // 当前对象的 first 和 second 会被初始化为这些值。 // 注意U 和 V 是临时 pair 对象的类型可以不同于当前 pair 的类型但必须能够赋值。带参数构造代码语言javascriptAI代码解释// 带参数构造函数用指定的值初始化 first 和 second 成员 pair(const first_type a, const second_type b); // first_type 和 second_type 是 pair 中 first 和 second 成员的类型。 // a 和 b 分别是初始化这两个成员的值。3.make_pairpair是一个模板类需要我们显示的传入两个类型T1 和 T2来实例化 pairT1 , T2对象。而使用map或者其他的关联式容器的时候我们需要为每个元素都传入一个键值对。每次插入到map中显示构造pair的对象的时候就会显的很繁琐。代码语言javascriptAI代码解释//手动构造 std::mapint, std::string m; m.insert(std::pairint, std::string(1, apple));为了简化这种操作C标准库提供了一个非常方便的工具——std::make_pair 函数模板。使用时我们不需要显示指定 pair 的类型它会自动推导类型减少显示传递类型的繁琐性。代码语言javascriptAI代码解释std::mapint, std::string m; m.insert(std::make_pair(1, apple));总结容器分类序列式容器线性序列结构存储元素本身元素位置独立关联式容器非线性结构存储键值对元素通过键访问操作效率更高键值对(pair)特性组成键(key) 值(value)键用于唯一标识值存储实际数据优势提供快速查找、插入和删除操作时间复杂度通常为O(log n)或O(1)pair的实用工具make_pair函数自动推导类型简化pair对象的创建使用对比代码语言javascriptAI代码解释// 繁琐的手动构造 m.insert(std::pairint, std::string(1, apple)); // 简化的自动推导 m.insert(std::make_pair(1, apple));关联式容器及其键值对机制是C中实现高效数据检索的重要工具特别适用于需要快速查找的场景。m.jtbdb.pro/post/11757.htmlm.jtbdb.pro/post/79719.htmlm.jtbdb.pro/post/24682.htmlm.jtbdb.pro/post/68046.htmlm.jtbdb.pro/post/44202.htmlm.jtbdb.pro/post/33995.htmlm.jtbdb.pro/post/84266.htmlm.jtbdb.pro/post/35555.htmlm.jtbdb.pro/post/46260.htmlm.jtbdb.pro/post/57197.htmlm.jtbdb.pro/post/35133.htmlm.jtbdb.pro/post/62442.htmlm.jtbdb.pro/post/57593.htmlm.jtbdb.pro/post/51913.htmlm.jtbdb.pro/post/75575.htmlm.jtbdb.pro/post/75777.htmlm.jtbdb.pro/post/93391.htmlm.jtbdb.pro/post/35575.htmlm.jtbdb.pro/post/57393.htmlm.jtbdb.pro/post/91717.htmlm.jtbdb.pro/post/37917.htmlm.jtbdb.pro/post/39713.htmlm.jtbdb.pro/post/19999.htmlm.jtbdb.pro/post/13943.htmlm.jtbdb.pro/post/17797.htmlm.jtbdb.pro/post/57117.htmlm.jtbdb.pro/post/53777.htmlm.jtbdb.pro/post/19555.htmlm.jtbdb.pro/post/97931.htmlm.jtbdb.pro/post/17917.htmlm.jtbdb.pro/post/59995.htmlm.jtbdb.pro/post/26004.htmlm.jtbdb.pro/post/33979.htmlm.jtbdb.pro/post/79795.htmlm.jtbdb.pro/post/19337.htmlm.jtbdb.pro/post/77371.htmlm.jtbdb.pro/post/13599.htmlm.jtbdb.pro/post/99553.htmlm.jtbdb.pro/post/99511.htmlm.jtbdb.pro/post/80848.htmlm.jtbdb.pro/post/19733.htmlm.jtbdb.pro/post/19711.htmlm.jtbdb.pro/post/33771.htmlm.jtbdb.pro/post/44668.htmlm.jtbdb.pro/post/15399.htmlm.jtbdb.pro/post/13491.htmlm.jtbdb.pro/post/93571.htmlm.jtbdb.pro/post/53177.htmlm.jtbdb.pro/post/11317.htmlm.jtbdb.pro/post/46046.htmlm.jtbdb.pro/post/68620.htmlm.jtbdb.pro/post/97313.htmlm.jtbdb.pro/post/19777.htmlm.jtbdb.pro/post/68466.htmlm.jtbdb.pro/post/37777.htmlm.jtbdb.pro/post/02280.htmlm.jtbdb.pro/post/99339.htmlm.jtbdb.pro/post/97377.htmlm.jtbdb.pro/post/57337.htmlm.jtbdb.pro/post/73913.htmlm.jtbdb.pro/post/73593.htmlm.jtbdb.pro/post/15335.htmlm.jtbdb.pro/post/95377.htmlm.jtbdb.pro/post/13795.htmlm.jtbdb.pro/post/91979.htmlm.jtbdb.pro/post/75913.htmlm.jtbdb.pro/post/33975.htmlm.jtbdb.pro/post/19779.htmlm.jtbdb.pro/post/31513.htmlm.jtbdb.pro/post/73931.htmlm.jtbdb.pro/post/17757.htmlm.jtbdb.pro/post/91519.htmlm.jtbdb.pro/post/97133.htmlm.jtbdb.pro/post/68808.htmlm.jtbdb.pro/post/68448.htmlm.jtbdb.pro/post/79953.htmlm.jtbdb.pro/post/97191.htmlm.jtbdb.pro/post/51199.htmlm.jtbdb.pro/post/44002.htmlm.jtbdb.pro/post/17513.htmlm.jtbdb.pro/post/15359.htmlm.jtbdb.pro/post/48444.htmlm.jtbdb.pro/post/55113.htmlm.jtbdb.pro/post/15319.htmlm.jtbdb.pro/post/37173.htmlm.jtbdb.pro/post/86240.htmlm.jtbdb.pro/post/77775.htmlm.jtbdb.pro/post/39511.htmlm.jtbdb.pro/post/97991.htmlm.jtbdb.pro/post/68886.htmlm.jtbdb.pro/post/53933.htmlm.jtbdb.pro/post/53191.htmlm.jtbdb.pro/post/51333.htmlm.jtbdb.pro/post/03059.htmlm.jtbdb.pro/post/53751.htmlm.jtbdb.pro/post/53711.htmlm.jtbdb.pro/post/39933.htmlm.jtbdb.pro/post/22428.htmlm.jtbdb.pro/post/71935.htmlm.jtbdb.pro/post/31731.htmlm.jtbdb.pro/post/53715.htmlm.jtbdb.pro/post/04680.htmlm.jtbdb.pro/post/84680.htmlm.jtbdb.pro/post/95751.htmlm.jtbdb.pro/post/55575.htmlm.jtbdb.pro/post/60686.htmlm.jtbdb.pro/post/71311.htmlm.jtbdb.pro/post/59115.htmlm.jtbdb.pro/post/77517.htmlm.jtbdb.pro/post/72178.htmlm.jtbdb.pro/post/79591.htmlm.jtbdb.pro/post/53353.htmlm.jtbdb.pro/post/95715.htmlm.jtbdb.pro/post/95315.htmlm.jtbdb.pro/post/24466.htmlm.jtbdb.pro/post/13553.htmlm.jtbdb.pro/post/91917.htmlm.jtbdb.pro/post/20820.htmlm.jtbdb.pro/post/08260.htmlm.jtbdb.pro/post/13535.htmlm.jtbdb.pro/post/91359.htmlm.jtbdb.pro/post/08466.htmlm.jtbdb.pro/post/55199.htmlm.jtbdb.pro/post/75957.htmlm.jtbdb.pro/post/33511.htmlm.jtbdb.pro/post/71837.htmlm.jtbdb.pro/post/99753.htmlm.jtbdb.pro/post/39173.htmlm.jtbdb.pro/post/55759.htmlm.jtbdb.pro/post/31135.htmlm.jtbdb.pro/post/91793.htmlm.jtbdb.pro/post/35155.htmlm.jtbdb.pro/post/75557.htmlm.jtbdb.pro/post/77539.htmlm.jtbdb.pro/post/15131.htmlm.jtbdb.pro/post/59351.htmlm.jtbdb.pro/post/86660.htmlm.jtbdb.pro/post/20080.htmlm.jtbdb.pro/post/37711.htmlm.jtbdb.pro/post/93935.htmlm.jtbdb.pro/post/31933.htmlm.jtbdb.pro/post/19939.htmlm.jtbdb.pro/post/48020.htmlm.jtbdb.pro/post/79739.htmlm.jtbdb.pro/post/77977.htmlm.jtbdb.pro/post/55715.htmlm.jtbdb.pro/post/51171.htmlm.jtbdb.pro/post/15959.htmlm.jtbdb.pro/post/99539.htmlm.jtbdb.pro/post/84686.htmlm.jtbdb.pro/post/13717.htmlm.jtbdb.pro/post/42020.htmlm.jtbdb.pro/post/20004.htmlm.jtbdb.pro/post/75159.htmlm.jtbdb.pro/post/57199.htmlm.jtbdb.pro/post/59975.htmlm.jtbdb.pro/post/00288.htmlm.jtbdb.pro/post/95793.htmlm.jtbdb.pro/post/35779.htmlm.jtbdb.pro/post/42820.htmlm.jtbdb.pro/post/57195.htmlm.jtbdb.pro/post/79597.htmlm.jtbdb.pro/post/31357.htmlm.jtbdb.pro/post/59399.htmlm.jtbdb.pro/post/55719.htmlm.jtbdb.pro/post/93313.htmlm.jtbdb.pro/post/88280.htmlm.jtbdb.pro/post/99155.htmlm.jtbdb.pro/post/48408.htmlm.jtbdb.pro/post/19359.htmlm.jtbdb.pro/post/15595.htmlm.jtbdb.pro/post/66246.htmlm.jtbdb.pro/post/11955.htmlm.jtbdb.pro/post/55917.htmlm.jtbdb.pro/post/91559.htmlm.jtbdb.pro/post/26280.htmlm.jtbdb.pro/post/39571.htmlm.jtbdb.pro/post/79175.htmlm.jtbdb.pro/post/17157.htmlm.jtbdb.pro/post/97975.htmlm.jtbdb.pro/post/57951.htmlm.jtbdb.pro/post/73173.htmlm.jtbdb.pro/post/59111.htmlm.jtbdb.pro/post/75513.htmlm.jtbdb.pro/post/37577.htmlm.jtbdb.pro/post/31537.htmlm.jtbdb.pro/post/84286.htmlm.jtbdb.pro/post/39931.htmlm.jtbdb.pro/post/93373.htmlm.jtbdb.pro/post/60664.htmlm.jtbdb.pro/post/20222.htmlm.jtbdb.pro/post/75531.htmlm.jtbdb.pro/post/55979.htmlm.jtbdb.pro/post/57793.htmlm.jtbdb.pro/post/39913.htmlm.jtbdb.pro/post/91113.htmlm.jtbdb.pro/post/19931.htmlm.jtbdb.pro/post/19973.htmlm.jtbdb.pro/post/31579.htmlm.jtbdb.pro/post/86226.htmlm.jtbdb.pro/post/77959.htmlm.jtbdb.pro/post/82068.htmlm.jtbdb.pro/post/55557.htmlm.jtbdb.pro/post/71795.htmlm.jtbdb.pro/post/75771.htmlm.jtbdb.pro/post/35591.htmlm.jtbdb.pro/post/95755.htmlm.jtbdb.pro/post/73139.htmlm.jtbdb.pro/post/19731.htmlm.jtbdb.pro/post/57157.htmlm.jtbdb.pro/post/84048.htmlm.jtbdb.pro/post/19519.htmlm.jtbdb.pro/post/79599.htmlm.jtbdb.pro/post/79771.htmlm.jtbdb.pro/post/73915.htmlm.jtbdb.pro/post/11359.htmlm.jtbdb.pro/post/42680.htmlm.jtbdb.pro/post/93377.htmlm.jtbdb.pro/post/64044.htmlm.jtbdb.pro/post/95579.htmlm.jtbdb.pro/post/31193.htmlm.jtbdb.pro/post/97353.htmlm.jtbdb.pro/post/15915.htmlm.jtbdb.pro/post/93537.htmlm.jtbdb.pro/post/55173.htmlm.jtbdb.pro/post/13591.htmlm.jtbdb.pro/post/31531.htmlm.jtbdb.pro/post/60020.htmlm.jtbdb.pro/post/28246.htmlm.jtbdb.pro/post/13159.htmlm.jtbdb.pro/post/17791.htmlm.jtbdb.pro/post/37515.htmlm.jtbdb.pro/post/33333.htmlm.jtbdb.pro/post/31711.htmlm.jtbdb.pro/post/77397.htmlm.jtbdb.pro/post/71595.htmlm.jtbdb.pro/post/91571.htmlm.jtbdb.pro/post/13517.htmlm.jtbdb.pro/post/15159.htmlm.jtbdb.pro/post/42082.htmlm.jtbdb.pro/post/13797.htmlm.jtbdb.pro/post/39515.htmlm.jtbdb.pro/post/66820.htmlm.jtbdb.pro/post/28080.htmlm.jtbdb.pro/post/53791.htmlm.jtbdb.pro/post/00204.htmlm.jtbdb.pro/post/22604.htmlm.jtbdb.pro/post/13735.htmlm.jtbdb.pro/post/86842.htmlm.jtbdb.pro/post/53339.htmlm.jtbdb.pro/post/77979.htmlm.jtbdb.pro/post/77173.htmlm.jtbdb.pro/post/53731.htmlm.jtbdb.pro/post/97179.htmlm.jtbdb.pro/post/75757.htmlm.jtbdb.pro/post/13375.htmlm.jtbdb.pro/post/59193.htmlm.jtbdb.pro/post/19355.htmlm.jtbdb.pro/post/17135.htmlm.jtbdb.pro/post/79317.htmlm.jtbdb.pro/post/95775.htmlm.jtbdb.pro/post/79915.htmlm.jtbdb.pro/post/26406.htmlm.jtbdb.pro/post/35735.htmlm.jtbdb.pro/post/79731.htmlm.jtbdb.pro/post/57771.htmlm.jtbdb.pro/post/22200.htmlm.jtbdb.pro/post/75313.htmlm.jtbdb.pro/post/99513.htmlm.jtbdb.pro/post/88666.htmlm.jtbdb.pro/post/71533.htmlm.jtbdb.pro/post/33153.htmlm.jtbdb.pro/post/88208.htmlm.jtbdb.pro/post/75193.htmlm.jtbdb.pro/post/99535.htmlm.jtbdb.pro/post/39991.htmlm.jtbdb.pro/post/91111.htmlm.jtbdb.pro/post/93753.htmlm.jtbdb.pro/post/73535.htmlm.jtbdb.pro/post/62428.htmlm.jtbdb.pro/post/95791.htmlm.jtbdb.pro/post/99157.htmlm.jtbdb.pro/post/17955.htmlm.jtbdb.pro/post/93177.htmlm.jtbdb.pro/post/95155.htmlm.jtbdb.pro/post/11795.htmlm.jtbdb.pro/post/73379.htmlm.jtbdb.pro/post/53115.htmlm.jtbdb.pro/post/60046.htmlm.jtbdb.pro/post/55755.htmlm.jtbdb.pro/post/86608.htmlm.jtbdb.pro/post/35397.htmlm.jtbdb.pro/post/53155.htmlm.jtbdb.pro/post/46008.htmlm.jtbdb.pro/post/51539.htmlm.jtbdb.pro/post/80080.htmlm.jtbdb.pro/post/55751.htmlm.jtbdb.pro/post/71153.htmlm.jtbdb.pro/post/15973.htmlm.jtbdb.pro/post/11573.htmlm.jtbdb.pro/post/08428.htmlm.jtbdb.pro/post/39115.htmlm.jtbdb.pro/post/15919.htmlm.jtbdb.pro/post/57115.htmlm.jtbdb.pro/post/71539.htmlm.jtbdb.pro/post/59997.htmlm.jtbdb.pro/post/40844.htmlm.jtbdb.pro/post/28226.htmlm.jtbdb.pro/post/99199.htmlm.jtbdb.pro/post/48739.htmlm.jtbdb.pro/post/11337.htmlm.jtbdb.pro/post/88022.htmlm.jtbdb.pro/post/91935.htmlm.jtbdb.pro/post/31937.htmlm.jtbdb.pro/post/82460.htmlm.jtbdb.pro/post/79351.htmlm.jtbdb.pro/post/71111.htmlm.jtbdb.pro/post/99577.htmlm.jtbdb.pro/post/59939.htmlm.jtbdb.pro/post/77571.htmlm.jtbdb.pro/post/66204.htmlm.jtbdb.pro/post/71513.htmlm.jtbdb.pro/post/17315.htmlm.jtbdb.pro/post/71577.htmlm.jtbdb.pro/post/79379.htmlm.jtbdb.pro/post/93337.htmlm.jtbdb.pro/post/17953.htmlm.jtbdb.pro/post/19579.htmlm.jtbdb.pro/post/57171.htmlm.jtbdb.pro/post/44082.htmlm.jtbdb.pro/post/82080.htmlm.jtbdb.pro/post/93915.htmlm.jtbdb.pro/post/35737.htmlm.jtbdb.pro/post/35115.htmlm.jtbdb.pro/post/66602.htmlm.jtbdb.pro/post/11335.htmlm.jtbdb.pro/post/48240.htmlm.jtbdb.pro/post/80608.htmlm.jtbdb.pro/post/39159.htmlm.jtbdb.pro/post/13519.htmlm.jtbdb.pro/post/93591.htmlm.jtbdb.pro/post/93319.htmlm.jtbdb.pro/post/33133.htmlm.jtbdb.pro/post/31511.htmlm.jtbdb.pro/post/15559.htmlm.jtbdb.pro/post/79531.htmlm.jtbdb.pro/post/82682.htmlm.jtbdb.pro/post/11733.htmlm.jtbdb.pro/post/99151.htmlm.jtbdb.pro/post/26668.htmlm.jtbdb.pro/post/20622.htmlm.jtbdb.pro/post/13937.htmlm.jtbdb.pro/post/91577.htmlm.jtbdb.pro/post/37111.htmlm.jtbdb.pro/post/75117.htmlm.jtbdb.pro/post/79171.htmlm.jtbdb.pro/post/95151.htmlm.jtbdb.pro/post/40862.htmlm.jtbdb.pro/post/37937.htmlm.jtbdb.pro/post/00820.htmlm.jtbdb.pro/post/59559.htmlm.jtbdb.pro/post/15351.htmlm.jtbdb.pro/post/62882.htmlm.jtbdb.pro/post/53999.htmlm.jtbdb.pro/post/77117.htmlm.jtbdb.pro/post/19591.htmlm.jtbdb.pro/post/73553.htmlm.jtbdb.pro/post/46826.htmlm.jtbdb.pro/post/53157.htmlm.jtbdb.pro/post/73351.htmlm.jtbdb.pro/post/33351.htmlm.jtbdb.pro/post/06408.htmlm.jtbdb.pro/post/97997.htmlm.jtbdb.pro/post/15535.htmlm.jtbdb.pro/post/53931.htmlm.jtbdb.pro/post/73911.htmlm.jtbdb.pro/post/00404.htmlm.jtbdb.pro/post/48220.htmlm.jtbdb.pro/post/00880.htmlm.jtbdb.pro/post/77333.htmlm.jtbdb.pro/post/31155.htmlm.jtbdb.pro/post/17957.htmlm.jtbdb.pro/post/22424.htmlm.jtbdb.pro/post/00408.htmlm.jtbdb.pro/post/15395.htmlm.jtbdb.pro/post/39759.htmlm.jtbdb.pro/post/35775.htmlm.jtbdb.pro/post/59391.htmlm.jtbdb.pro/post/73155.htmlm.jtbdb.pro/post/31951.htmlm.jtbdb.pro/post/39939.htmlm.jtbdb.pro/post/42208.html