I'm using the facebook api to retrieve a list of a user's photos. I'm using this to work out the user's close friends by seeing who has been tagged the most in the user's photos. So what I have the list of the tagged users (there will be duplicates). What I want to do is go through each tag and insert the user into a data structure. If the user is already there I want to increase that user's c开发者_高级运维ount by one. At the end I want the list ordered so I can 'rank' the friends. What data structure will be best for this?
Step 1:
Use an associative container. Map from UserId to user's count. Keep adding new users, and updating the user's count as you process more data.
Step2:
Copy all the users to another associative container, Now the key should be a pair(user's count, UserId).
You can now iterate over the 2nd container and have your items in order.
If you're using C++, you can use map for step 1, and set for step 2.
精彩评论