How do we use dictionaries and maps in C++? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How do we use dictionaries and maps in C++?

Just started learning about it and I can't understand its definition as well as how and when to use it. By the way, I also want to ask about some function that can be used along with maps

5th Dec 2020, 9:15 AM
Hữu Đức Phạm
Hữu Đức Phạm - avatar
1 Answer
+ 5
The concept is simple. You have a key stored in a quickly searchable manor. It is tied to a value. Both key and value can be anything. The key data must provide a comparison so a binary search tree can be used. Lets say you wish to count usages of every word in a book. The word would be the key. You would find each word in the book. If it is not currently in the dictionary, you add it with a value of one. Otherwise, you increment the value. Once all words were processed, you could display the ten most or least popular words. There are many different ways to use it. You could map an user menu number to the function to process the request. Make an AI search words for the responses to give. Compilers use it to map names to variables, functions, excetera. Ignoring language, normally provide functions are add a new map, delete an existing map, update or add a map, clear all maps, search the dictionary for a value. Language variations might include adding or removing many maps, filtering maps, making a list.
6th Dec 2020, 7:17 AM
John Wells
John Wells - avatar