map当中的count和find以及map和unordered_map

使用count,返回的是被查找元素的个数。如果有,返回1;否则,返回0。注意,map中不存在相同元素,所以返回值只能是1或0。

if(hash_table.count(other) && hash_table[other] != i){

使用find,返回的是被查找元素的位置,没有则返回map.end()。

if(hash_table.find(other) !=hash_table.end()  && hash_table[other] != i){

map与unordered_map相比:

map底层实现为红黑数,undered_map底层实现为哈希表,两者均不能有重复的建,均支持[]运算符

map与multimap相比:

两者底层实现均为红黑树,但是multimap支持重复的键,不支持[]运算符

猜你喜欢

转载自blog.csdn.net/qq_34269988/article/details/87989456