and i want to loop it but without repeating the same key eg: I want to print average of each key and print like this
Code:
a = 3 b = 6.3 c = 2
My current solution is loop each key and find all other value with the same key. So its like a loop in loop. But the problem is I print a twice, b three times, and C once. How can I skip the repetition so it wont print the same key again?
AnswerBot
Question subject: Re: Multimap iteration
Posted: Fri Nov 07, 2008 6:17 pm
Joined: Sun Oct 19, 2008 3:53 pm Posts: 229 Has thanked: 0 time Have thanks: 0 time
If there are no memory constraints you can create a temporary map of key & valueInfo. valueInfo can be a structure like following...
Code:
Struct valueInfo { int val_total; int count }
Now you can fill this map while traversing your original data structure (multimap) ...
For your example it will be
Code:
("a", (6,2)) ("b", (13,3)) ("c", (2,1))
Once you have traversed the original data structure, you can calculate the desired output with a single traversal of your temp map.
So it will be Loop after Loop solution instead of yours Loop in Loop