我很难理解C ++中的地图 [英] I am struggling to understand what maps are in C++

查看:76
本文介绍了我很难理解C ++中的地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在读一本名为Alex Allain的C ++跳转的书,他引入了一系列代码如下地图:



I am reading a book called jumping into C++ by Alex Allain and he has introduced maps with lines of code like:

map<string, string> name_to_email;




name_to_email[ "Alex Allain" ] = "webmaster@cprogramming.com";




cout << name_to_email[ "Alex Allain" ];





他一直在说地图是多么有用但问题是,我无法理解是什么他们的好处是。它们的大小可以更改(如链表,二叉树或向量),它们可以为每个节点存储多个值(如链表或二叉树),它们可以存储不同类型的值(如链表或二叉树) 。那究竟是什么让这些地图变得有用呢?请简单解释一下,因为我很难理解复杂的编程术语。



我尝试了什么:



我曾尝试阅读有关地图使用原因的书籍说明,并尝试在线阅读解释为何使用它们但无法理解的原因。



And he keeps saying how useful maps are but the problem is, I can't understand what their benefit is. Their size can be changed (like a linked list, binary tree or vector), they can store multiple values per node (like a linked list or binary tree) and they can store values of different types (like a linked list or binary tree). So what exactly is it that makes these maps useful. Explain in simple terms please as I will struggle to understand sophisticated programming terms.

What I have tried:

I have tried reading the books explanation about why maps are used and tried reading explanations online about why they're used but couldn't really understand either.

推荐答案

它们非常有用的主要原因是它们可以非常快速地搜索和查找感兴趣的值。地图中的第一项称为密钥,用于搜索。通常二叉树或类似的东西保存幕后数据,第一个值是标识符搜索正在查找。搜索的速度是地图的强度。
The primary reason they are so useful is they make searching and finding values of interest very fast. The first item in the map is called the key and it used for searching. Usually a binary tree or something similar holds the data behind the scenes with the first value being the identifier searches are looking up. The speed of the searching is the strength of maps.


这篇关于我很难理解C ++中的地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆