I have a list of doubles that need to be sorted and changed so that there are no two numbers that are the same (difference smaller then 0.05) and I need to do it fast. I don't care about preserving order for values that are the same.
What I'm doing right now is:
List<double> values;
bool sortfunction(double a, double b)
{
return a < b;
}
.....
qSort(values.start, values.end, sortfunction);
for(int i = 0; i < values.count() - 1; i++)
{
if(values[i] == values[i+1])
{
values[i+1] += 0.1;
}
}
But the problem is with lists like { 0. ,0. ,0. ,5. ,6.3 }
. The result being { 0. ,0.1 ,0. ,5. ,6.3 }
. Can you think of something that does not require multiple passes of sorting?