Since you do not need to output
all the data in a sorted form,
and obviously not store the data sorted somewhere,
I would probably not try to solve the problem with any sort at all.
I see the problem more as a
data extraction problem.
- Read all lines, one by one.
- Find the highest value in every line.
- Check if you already have this state in your hash.
- If not, save the state with the highest value found on the line to the hash.
- If already in the hash and the newly found value is higher than the highest value already stored for this state, replace with the new value.
- Loop until end of file.
- You will probably have one hash for max and another hash for min temp, but that's not necessary. You could store it all in the same hash if you prefer.
This is Bepa