I have a function that does some computing and set the value returned into my vector.
#include <vector>
#include <algorithm>
#include <iostream>
void VectorLoop(vector<ClassName>& Vector)
{
float TempFloatVariable = 0.0;
int count = 0;
int update = 0;
while (count != Vector.size())
{
if (Vector[count].getValue() == 100.0) //I hardcode this so i can check if the Value is empty or not
{
//code that set all of the variable from the vector's memory's object
TempFloatVariable = AnotherClass.Formula //does the computing and return the value
//code that gets value from object for overloading
//code that gets value from object for overloading
//code that gets value from object for overloading
Vector[count].setValue(TempFloatVariable);
update++;
}
else
{
count++;
}
}
cout << "Computation completed! (" << update << " record(s) were updated)" << endl;
}
After all of the computing is done, I want to sort them from highest to lowest, base on the Value, but I have no idea how to do so, i tried to hard code it, pulling values out manually 1 by 1 to do comparison, but kept failing. And that would defeat the purpose of using vector, there are many examples of sorting using vector, but 90% of it are int values stored in the vectors.
std::sort(Vector.begin(), Vector.end(), [](const PointTwoD& a, const PointTwoD& b) { return a.getcivIndex() > b.getcivIndex(); } );coutpart ? @IgorTandetnik