I have a program, where I enter some numbers in a C++ STL list. I want to find the most frequent element of the list. My question is what am I doing the wrong way, since the program does not work as expected?
// List.cpp : Defines the entry point for the console application.
//
#include <iostream>
#include <algorithm>
#include <list>
#include <vector>
using namespace std;
char number;
int counter;
list <char> l;
vector <int> m;
list <char>::iterator START;
void countRepetition();
int main()
{
    do {
        number = getchar();
        if (number != '0') {
            l.push_back(number);
        }
    } while (number != '0');
    /*for (START = l.begin(); START != l.end(); START++) {
        m.push_back(countRepetition(*START));
    }
    for (int i = 0; i < m.size(); i++) {
        cout << m[i] << endl;
    }
    */
     countRepetition();
    auto x = max_element(m.begin(), m.end());
    cout << *x << endl;
    return 0;
}
void countRepetition() {
    for (auto i = l.begin(); i != l.end(); i++) {
        for (auto j = l.begin(); j != l.end(); j++) {
            if (*i == *j) {
                counter++;
            }
            m.push_back(counter);
        }
    }
}
 
     
    