2013 2013 - 1 year ago 109
C++ Question

How to push multiple data in multimap in c++?

I made an implementation of dfs in c++ by multimap container in this way:

multimap<int, int>g;

And we could add edges in the graph in this way:


Now I'm going to implement the Khushkal Algorithm by multimap. But in this case I got one more extra data per node , the weight. So now I need to store, (1,2,3) for example , triple data in the multimap.

Then what will be the multimap declaration look like??
And how could I insert such nodes?

Answer Source

You will have to map an item on another item. Pick what you would like to use as key. If you decide on one key and two values, you map an int on a pair of ints. You can also opt to use a pair as key and map it on an int.

If you just would like to store pairs or tuples of three items, it is better to use an (unordered)set of these data members.

Option 1:

multimap<int, pair<int,int>>

Option 2:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download