What is the difference between set vs map in C++?

前端 未结 5 1213
广开言路
广开言路 2020-12-24 06:06

I am still confused by the differences between the map and set datastructures in STL. I know set is storing the values in a sorted way, what about map? Does it store the val

5条回答
  •  孤城傲影
    2020-12-24 06:38

    A map stores keys sorted. It maps keys to values. Usually it is implemented as a binary search tree (red-black tree) for keys. A set is a map where values are irrelevant. unordered_map and unordered_set (new in C++11) store keys unsorted and use hash table for search.

提交回复
热议问题