Map
Attribute
Each key in the map(no matter what type) should be unique.
Cannot sort the value directly using map structure. Store key and value in pair and put in a vector. Use cmp to compare the sort values.
Type of set
map
Elements in the map are sorted in ACSENDING order by key.
Implement balanced tree structure, the time complexity is O(logN) for insert/delete.
unordered_map
The elements in the map are NOT ordered. Save running time.
time complexity is O(1) for insert.
Functions
empty()
if(!map.empty()) means if the map is not empty, then go inside the if-block.
size()
map.size() will return the numbers of elements in the map.
insert()
map[key] = value or map.insert({key, value}).
find()
Get the iterator to element. map.find(key) == map.end() means the key does not exist in the map.
count()
Count elements of the key. if map.count(key) == 0 means the key does not exist in the map.