How are multimaps useful


Wed Apr 14 2021 17:14:09 GMT+0000 (UTC)

Saved by @wowza12341

Multimaps are useful when working with duplicate values. For example, in a telephone directory application you could use a map to store a customer's name and their telephone number. However, if your directory covers a large area, it is quite likely that there will more than one person with the same name; there could be two different customers who are both called "John Smith". If you used a map, then you would have a problem when you try to add the second "John Smith". If you call insert(), then the telephone number for the first "John Smith" will be returned when you query the name. If you use [], then you will get the number of the second "John Smith". Either way, there will only be one entry for John Smith and there will be some times when the returned number will be wrong. If you use multimap instead, then there will be two entries for "John Smith", one for each telephone number. When you query the name, you will get both numbers and then you can (for example) ask for extra information to decide which is the correct one.