Use of multisets in C duplicate

0 votes
I understand the use of sets in C++, but why are there multisets?

What are some examples of real-world uses for multisets?

This argument may be extended to unordered multisets as well; what distinguishes it from utilising a vector, and what benefits and drawbacks does it provide?
Jun 27, 2022 in C++ by Nicholas
• 7,760 points
462 views

1 answer to this question.

0 votes

Because a multi-set does not need the storage of single-element objects. 

You're considering storing anything in a multi-set, such as a string. 

But it is not its intended use. 

You may use whatever struct you want and compare it to a single element in the struct.

As an example:

struct PhoneBookEntry
{
    std::string name;
    std::string phoneNumber;
}

There's no reason to have a single entry per name in a phone book in this unsophisticated "phone book" entry. 

There may be a lot. 

So you create a PhoneBookEntry multiset and make the comparator by name. 

You may have many phone numbers with the same name this way.

You could assume that a map is more appropriate for this. 

However, this is only one example. 

A multiset is used when you don't require a key/value pair but need the search features of a set with several entries per key.

answered Jun 27, 2022 by Damon
• 4,960 points

Related Questions In C++

0 votes
0 answers

Use of min and max functions in C++

Are std::min and std::max better than fmin ...READ MORE

Jun 2, 2022 in C++ by Nicholas
• 7,760 points
595 views
0 votes
0 answers

What is the difference between cout, cerr, clog of iostream header in c++? When to use which one?

I looked up the differences between cout, ...READ MORE

Jul 27, 2022 in C++ by Nicholas
• 7,760 points
723 views
0 votes
1 answer

How to use std::sort to sort an array in C++

We receive std::begin and std::end in C++0x/11, which are overloaded for arrays: #include <algorithm> int main(){ int v[2000]; ...READ MORE

answered Jun 1, 2022 in C++ by Damon
• 4,960 points
1,148 views
0 votes
1 answer

Cases of static and dynamic binding in C++

When an object's static type is used to associate it with a member function, this is known as static binding (understand the type of its class). When a pointer or reference is associated with a member function based on the dynamic type of the object, this is known as dynamic binding (understand the instance of the variable at runtime). Before continuing, keep in mind that dynamic binding only works with pointers, references, and virtual functions for the base class. Because everything needed to call the function is known at compile time, the first call is a static binding (also known as early binding). Derived1 d1(1, 10); d1.display_data(); You already know that the d1 instance is a Derived1 automatic variable, and that it will call the Derived1::display data method (). The first condition is incorrect: d1 is neither a pointer nor a reference. The second condition isn't acceptable:  There is no virtual Derived1::display data. The second call is for ...READ MORE

answered Jun 7, 2022 in C++ by Damon
• 4,960 points
697 views
0 votes
1 answer

C++ multiset, return key at position?

A set (or multiset) is typically represented ...READ MORE

answered Jun 27, 2022 in C++ by Damon
• 4,960 points
410 views
0 votes
1 answer

setuptools: build shared libary from C++ code, then build Cython wrapper linked to shared libary

There is a seemingly undocumented feature of setup that ...READ MORE

answered Sep 11, 2018 in Python by Priyaj
• 58,020 points
693 views
0 votes
1 answer

setuptools: build shared libary from C++ code, then build Cython wrapper linked to shared libary

There is a seemingly undocumented feature of setup that ...READ MORE

answered Sep 21, 2018 in Python by Priyaj
• 58,020 points
2,409 views
0 votes
1 answer

How to pass large records to map/reduce tasks?

Hadoop is not designed for records about ...READ MORE

answered Sep 25, 2018 in Big Data Hadoop by Frankie
• 9,830 points
1,459 views
0 votes
1 answer

Use of "this" keyword in C++ [duplicate]

Yes, it is optional and generally omitted.  However, it may be essential for accessing variables after they have been overridden in the scope: Person::Person() { int age; ...READ MORE

answered Jun 20, 2022 in C++ by Damon
• 4,960 points
471 views
0 votes
1 answer

Use of min and max functions in C++

The functions fmin and fmax are designed ...READ MORE

answered Jun 21, 2022 in C++ by Damon
• 4,960 points
11,302 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP