"John H." <oldman_fromthec@yahoo.com> ha scritto nel messaggio
news:01a7a4ed-6137-43f2-baed-04635caad658@30g2000yqu.googlegroups.com...
Yes it can be done.
If you post some of your efforts at doing this so far, we might be
able to help you more.
#include <iostream>
#include <map>
using namespace std;
#define length(x) (sizeof (x) / sizeof *(x))
int main()
{
int a[] = {1,2,9,5,6,4,8,1,2,1,7,9,8,9,9,9,9,9};
map<int,int> freq;
for ( size_t i = 0; i < length ( a ); i++ )
{
++freq[a[i]];
}
map<int,int>::const_iterator it = freq.begin();
while ( it != freq.end() )
{
cout<< it->first <<": "<< it->second <<endl;
++it;
}
return 0;
}
That's a good start. Now all you need to in your second loop is remember the
(*it is of type std::pair<int, int>). After the loop, the first member of