Jump to content
  • Advertisement
Sign in to follow this  
luasitdown

same key

This topic is 4833 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a list node. every node has 2 value :type and data type may be the same . so I want to cut the list of node according to same type, put node with same type to a list. finally I will get several lists. every list of node have same type. for (node in list) { if (node.type = =1) push(node)into list1; if (node.type = =2) push(node)into list2; .......etc } So what is fast method? How about multimap ?

Share this post


Link to post
Share on other sites
Advertisement
So you want to sort a list of multiple types into multiple lists containing only one type each?

I don’t see any other way than to iterate over each element of the list, check its type, and move in into its destination list, essentially what you have there. Unless I misunderstand what your trying to do.

Share this post


Link to post
Share on other sites
Sort the list by type.
Use find_if to find the first element with type.
Iterate through list until type no longer matches.

If you really need separate lists, use splice.

Share this post


Link to post
Share on other sites
Quote:
Original post by Grain
So you want to sort a list of multiple types into multiple lists containing only one type each?

I don’t see any other way than to iterate over each element of the list, check its type, and move in into its destination list, essentially what you have there. Unless I misunderstand what your trying to do.
how about multimap ?

Mabye it could do great / hard work for it.

Share this post


Link to post
Share on other sites
Hey! Look


std::multimap<type,node> nodeMap;
// for only one type
multimap<type,node>::iterator l = nodeMap.lower_bound(type);
multimap<type,node>::iterator u = nodeMap.upper_bound(type);
multimap<type,node>::iterator it;

for (it=l;it!=u;it++)
{
it->second// you get it
}
nodeMap.count(type)//same type count




But I still need to a list of type.so I can iterate all type.
How to directly get a type list ???

[Edited by - luasitdown on August 23, 2005 11:22:46 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!