亚马逊网站做购物比价的网站有哪些

diannao/2026/1/17 7:43:11/文章来源:
亚马逊网站,做购物比价的网站有哪些,网站建设系统总体结构功能图,网页搭建公司STL 中map的用法详解 Map是STL的一个关联容器#xff0c;它提供一对一#xff08;其中第一个可以称为关键字#xff0c;每个关键字只能在map中出现一次#xff0c;第二个可能称为该关键字的值#xff09;的数据处理能力#xff0c;由于这个特性#xff0c;它完成有可能在…STL 中map的用法详解 Map是STL的一个关联容器它提供一对一其中第一个可以称为关键字每个关键字只能在map中出现一次第二个可能称为该关键字的值的数据处理能力由于这个特性它完成有可能在我们处理一对一数据的时候在编程上提供快速通道。这里说下map内部数据的组织map内部自建一颗红黑树(一种非严格意义上的平衡二叉树)这颗树具有对数据自动排序的功能所以在map内部所有的数据都是有序的。 下面举例说明什么是一对一的数据映射。比如一个班级中每个学生的学号跟他的姓名就存在着一一映射的关系这个模型用map可能轻易描述很明显学号用int描述姓名用字符串描述(本篇文章中不用char *来描述字符串而是采用STL中string来描述),下面给出map描述代码: Mapint, string mapStudent; 1.    map的构造函数 map共提供了6个构造函数这块涉及到内存分配器这些东西略过不表在下面我们将接触到一些map的构造方法这里要说下的就是我们通常用如下方法构造一个map Mapint, string mapStudent; 2.    数据的插入 在构造map容器后我们就可以往里面插入数据了。这里讲三种插入数据的方法 第一种:用insert函数插入pair数据下面举例说明(以下代码虽然是随手写的应该可以在VC和GCC下编译通过大家可以运行下看什么效果在VC下请加入这条语句屏蔽4786警告  pragma warning (disable:4786) ) #include map #include string #include iostream Using 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 - second end; } } 第二种用insert函数插入value_type数据下面举例说明 #include map #include string #include iostream Using 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 iostream Using 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 iostream Using 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 iostream Using 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 iostream Using 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 iostream Using 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 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 iostream Using 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的话返回的就是3 Equal_range函数返回一个pairpair里面第一个变量是Lower_bound返回的迭代器pair里面第二个迭代器是Upper_bound返回的迭代器如果这两个迭代器相等的话则说明map中不出现这个关键字程序说明 #include map #include string #include iostream Using 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则说明是空map 7.       数据的删除 这里要用到erase函数它有三个重载了的函数下面在例子中详细说明它们的用法 #include map #include string #include iostream Using 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 string Using 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 string Using 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)); } 10.   另外 由于STL是一个统一的整体map的很多用法都和STL中其它的东西结合在一起比如在排序上这里默认用的是小于号即less如果要从大到小排序呢这里涉及到的东西很多在此无法一一加以说明。 还要说明的是map中由于它内部有序由红黑树保证因此很多函数执行的时间复杂度都是log2N的如果用map函数可以实现的功能而STL  Algorithm也可以完成该功能建议用map自带函数效率高一些。  转载于:https://www.cnblogs.com/xiaojinma/archive/2012/12/06/2805539.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/91143.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

网站首页设计思路注册公司需要哪些条件

一、引言 1. vim是一款功能强大的文本编辑器,如果使用熟练,将会有效帮助我们提高编辑文本、程序的效率。vim编辑器的上手使用门槛比较高,很多人怯于要记很多命令,往往在学习的初期阶段就望而却步。 2. vim的学习需要不断的练习、使…

集团公司网站案例网站提示页面设计

RabbitMQ遵循AMQP协议,自身采用Erlang RabbitMQ工作模式 生产者发消息,启动多个消费者实例来消费消息,每个消费者仅消费部分信息,可达到负载均衡的效果。 RabbitMQ三种常用交换机类型: 交换机主要起调度分发作用。 …

网站与微信深圳市宝安区

一,系统显示方向 1. 概述 Android的旋转显示,主要运用于广告机。Android的旋转,包括图形UI的旋转、鼠标和遥控器的旋转及媒体旋转。 下图为竖屏UI的绘制坐标系和显示坐标系。 2. 功能说明 方案依据Android原生的旋转原理设计&#xff0c…

中国做外贸的网站有哪些内容大专软件技术好就业吗

相信不少小伙伴面试时,都被问到过这样一个问题:进程和线程的区别是什么?大学老师会告诉我们:进程是资源分配的基本单位,线程是调度的基本单位。说到调度,就不得不提到CPU的上下文切换了。 何为CPU上下文切换…

做第三方支付网站违法吗东营网站建设专业定制

为了方便起见,Komodor 提供了一个简单的 Web 界面,以帮助您监控 Kubernetes 集群的状态。它拥有付费和免费增值计划,除了在出现问题时通知用户外,还拥有一系列方便的工具,用于跟踪和管理集群中部署的资源的状态。让我们…

AD这个软件做网站用得着吗做视频网站资源采集

程序员无言 2020-07-07一、C语言程序的构成与C、Java相比,C语言其实很简单,但却非常重要。因为它是C、Java的基础。不把C语言基础打扎实,很难成为程序员高手。1、C语言的结构先通过一个简单的例子,把C语言的基础打牢。C语言的结构…

夜场网站建设域名查询ip网站

最近公司领导要求为公司制作一本企业宣传画册,用来展示我们的产品和服务,增加品牌影响力。可是,像我这种零基础的小白,完全不知道如何制作啊?对此我感到很焦虑,怕做不好影响公司形象,也怕耽误时…

如何判断网站有cdn加速免费页面网站

使用prettytable库按表格的形式美化输出结果 效果如图: 表格中可接收列表格式的数据,列表中装字符串 # 引入模块 import prettytable as pt# 创建表格与表头,包含五列,分别为train-epoch,class,precisio…

典型的电子商务网站有哪些公司网站设计要多少钱

今天大家分享的是一个专注于NetCore平台图像处理的开源项目,老实说为这篇文章取名字想了5分钟,可能是词穷亦或是想更好的表达出这款开源项目的作用;这个项目在图像处理方面有很多功能,如:缩放,裁剪&#xf…

泉州网站建设技术外包承德企业网站建设公司

map 类似其它语言中的哈希表或字典,以key-value形式存储数据key必须是支持或!比较运算的类型,不可以是函数、map或sliceMap查找比线性搜索快很多,但比使用索引访问数据的类型慢100倍 Map使用make()创建,支持:这种简写方式 make([k…

招工网站服务官方网站minecraft

整理相关资料,阅读c#课本转载于:https://www.cnblogs.com/JL3Peanut/p/10032318.html

网站数据包括哪些内容重庆建工集团建设网站

近年来,华为自主研发的鸿蒙操作系统(HarmonyOS)引起了广泛的关注和讨论。鸿蒙系统不仅标志着华为在软件领域的一次重大突破,也预示着全球智能设备市场格局的潜在变化。本文将深入探讨鸿蒙系统的兴起、其在市场上的表现以及对程序员…

长沙网站建设流程公司网站宣传自己做的灯展

动画是当今用户界面的关键因素。当使用核心动画的时候,动画是自动完成的。没有动画的循环和计数器。你的应用程序不负负责重绘,也不负责跟踪动画的当前状态。动画在独立线程里面自动执行,没有和你的应用程序交互。本章提供了对动画类的概览&a…

推荐十个国外网站wordpress 调用备案号

关于Git的一些基础用法 1. 前言2. 使用GitHub/gitee创建项目2.1 创建账号2.2 创建项目2.3 下载仓库到本地2.4 提交代码到远端仓库2.5 查看日志2.6 同步远端仓库和本地仓库 1. 前言 首先说一个冷知识(好像也不是很冷),Linux和git的创始人是同…

公司建设网站怎么作账怎么添加网站 多少钱

使用Maven编译Tomcat源码 准备工作 编译工具:Intellij Idea 15.0.2Tomcat版本:7.0.69 下载链接JDK版本:1.7.0_80Maven版本:3.05编译步骤 1. 在工作空间中建立目录 TomcatSource,下载源码解压到此文件夹,完成后目录结构…

专业简历制作网站有哪些wordpress 在线答题

2019独角兽企业重金招聘Python工程师标准>>> Builder模式定义: 将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示. Builder模式是一步一步创建一个复杂的对象,它允许用户可以只通过指定复杂对象的类型和内容就可以构建它们…

做地方门户网站的资质海口建网站公司

Hi, 大家好,今天阿目分享的是一个嵌入式软件面试的常见问题,内存分布或者说程序在内存中的布局,我们写的程序是按照怎么的准则放在内存中的? 一般有操作系统的嵌入式设备,都会有一个Bootloader, 它负责在上电后初始化…

免费建站网站一级大录像不卡电子商务平台经营者对于竞价排名的商品或服务

最近项目中大量使用了Spring Cloud Feign来对接http接口,踩了不少坑,也产生了一些对RESTFUL接口设计的想法,特此一篇记录下。SpringMVC的请求参数绑定机制了解Feign历史的朋友会知道,Feign本身是Netflix的产品,Spring …

中国铁塔公司招聘网站企业网站建设相关书籍在线阅读

grails框架框架通过为程序员提供一些有用的功能来简化应用程序开发过程。 由于开发人员的普遍使用,Java框架经常被开发人员使用。 您可以在市场上找到各种Java开发框架。 新手开发人员经常在论坛上发布一个常见问题:“哪种Java框架是最好的?”…

哪个网站推荐做挖机事的贵州 网站备案

内容包含系统能控性结构分解、系统能观测性结构分解以及系统结构规范分解原理,线性系统的内部稳定、BIBO稳定概念及其性质 转载于:https://www.cnblogs.com/ERFishing/p/10314720.html