Hi I have no idea how set works when I set <char> (Function(map<char ,int>...)
Edit :
//Set map
map<char, int> frequency;
Secondly:
map<char, int> count_chars(const string input) {
// Given a map
map<char, int> frequency;
// Populate it with the count of each character in the input
//for loop to populate plus count
for(int i = 0; i < size; i++){
frequency[input[i]]++;
}
return frequency;
}
Third:
//Find highest occurence of character
char max_freq(map<char, int> frequency) {
int key = 0;
for (pair<char, int> elements : frequency){
// highest = element.first;
if(key <= elements.second){
key = elements.second;
highest = elements.first;
}
}
return highest;
}
Lastly :
//I added set<char> s into the code below and it solved the syntax error. Any better solutions?
enter code here
// Below is what I wrote, I am supposed to find max occurrences of the character but I think I do not understand the syntax.
set<char> max_freq(map<char, int> frequency)
{
char high;
int key = 0;
for (pair<char, int> elements : frequency)
{
if (key <= elements.second)
{
key = elements.second;
high = elements.first;
frequency[high];
}
}
return frequency;
}
I keep getting this error:
Map.cpp:117:12: error: could not convert 'frequency' from 'std::map' to 'std::set' return frequency;