I'm currently using a SortedList in a loop to sort some values in descending order:
for(...)
{
float rawValue;
float offset;
sortedList.Add(rawValue + offset, index);
}
I'm interested in finding out if sortedList[0]
(i.e. the entry with the highest rawValue+offset) is also the highest entry if we had sorted the entries by their raw values without the offsets?
The obvious solution is to have another sortedRawValuesList populated in the same loop, but I think there are quicker and more memory efficient ways of achieving that?
Thanks!
Could you not simply keep track of the highest rawValue as you iterated? If the offsets change through each iteration, you would probably want to save the offset as well.
float highestRawVal = float.MinVal;
float offset_ForHighestRawVal = float.MinVal;
for(...)
{
float rawValue;
float offset;
sortedList.Add(rawValue + offset, index);
if(highestRawVal < rawVal)
{
highestRawVal = rawValue;
offset_ForHighestRawVal = offset;
}
}
if (highestRawVal + offset_ForHighestRawVal == sortedList[0])
Console.WriteLine("They Match");
Then you could simply check afterwards if they match.