I made a function that returns a vector
with all the prime factors of an integer, and I am trying to make another function that creates a map
from that vector
.
However, I am getting some typicall illegal memory access error and I cannot find what it is. I think it happens inside the for
loop of the map<int, int> factorizacion(vector<int>)
function.
I hope I could get some help here.
I could post the whole program but I'll just stick to the function that's causing the issue. Just ask for the rest of the code in case you need to give it a look.
map<int, int> factorizacion(vector<int> v) {
map<int, int> m;
while (!v.empty()) {
int elto = v.front();
int ctd = 0;
for (vector<int>::iterator it = v.begin(); it != v.end(); ++it) {
if (*it == elto) {
++ctd;
v.erase(it);
}
}
m[elto] = ctd;
}
return m;
}