Reputation: 7
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:
g.insert(make_pair(1,2));
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?
Upvotes: 0
Views: 162
Reputation: 1517
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:
multimap<pair<int,int>,int>
Upvotes: 1