Hi friends,
I have a map containing an int as key and a struct as second value, read from file.
I need to update the second column with value obtained by the last value (bigger one) + 1. A kind of sequential code ...
I tried to use the max_element function but didn't work well. I don't know if I made mistake. I commented at the spot where I need to insert a code. (//receiveLastCode =).
E.G.:
1 1 0 0 1
2 2 0 0 1
6 3 0 0 1
7 4 0 0 1
10 5 0 0 1
999 6 0 0 1
1000 7 0 0 1
3 0 14 20 0
8 0 0 1000 0
14 0 999 6 0
20 0 10 1000 0
30 0 999 7 0
77 0 3 8 0
500 0 77 0 0
PS: The next code should be 8! There are codes from 1 to 7 until this point.
Any kind of suggestion will be very appreciated.
Cheers,
while(ZerosRemaning(IndivAuxIDSortedMap))
{
for (it4 = IndivAuxIDSortedMap.begin(); it4 != IndivAuxIDSortedMap.end(); ++it4)
{
iterSearch = IndivAuxIDSortedMap.find(it4->second.father);
if (iterSearch != IndivAuxIDSortedMap.end())
{
std::cout << "Father RE-CODED Value is: " << iterSearch->second.auxID << '\n';
receiveSearchFather = iterSearch->second.auxID;
}
else std::cout << "FATHER(Key) is not in my_map" << '\n';
iterSearch = IndivAuxIDSortedMap.find(it4->second.mother);
if (iterSearch != IndivAuxIDSortedMap.end())
{
std::cout << "Mother RE-CODED Value is: " << iterSearch->second.auxID << '\n';
receiveSearchMother = iterSearch->second.auxID;
}
else std::cout << "FATHER(Key) is not in my_map" << '\n';
iterSearch = IndivAuxIDSortedMap.find(it4->second.father);
if (iterSearch != IndivAuxIDSortedMap.end())
{
std::cout << "Father's Level Value is: " << iterSearch->second.level << '\n';
receiveSearchFatherLevel = iterSearch->second.level;
}
else std::cout << "Father's Level is not in my_map" << '\n';
iterSearch = IndivAuxIDSortedMap.find(it4->second.mother);
if (iterSearch != IndivAuxIDSortedMap.end())
{
std::cout << "Mother's Level Value is: " << iterSearch->second.level << '\n';
receiveSearchMotherLevel = iterSearch->second.level;
}
else std::cout << "Mother's Level is not in my_map" << '\n';
if(receiveSearchFather !=0 and receiveSearchMother!=0)
{
levelUpdated = returnGreater(receiveSearchFatherLevel,receiveSearchMotherLevel)+ 1;
IndivAuxIDSortedMap[it4->first].level = levelUpdated;
std::cout << "Updated Level is: " << IndivAuxIDSortedMap[it4->first].level << endl;
// UPDATE THE AUX_CODE WITH THE NEXT NUMBER OF second column .
//receiveLastCode = ;
}
}
}