Answers for "Traversing a map"

C++
0

Traversing a map

int arr[] = { 1, 1, 2, 1,  3, 1, 4, 3 };
map<int, int> m;
for (auto i: arr)
	m[arr[i]]++;
cout << "Element  Frequency" << endl;
for (auto& [k,v] : m) // Since c++17
	cout << k << "   " << v << endl;
Posted by: Guest on April-30-2021

Browse Popular Code Answers by Language