I have two vectors of float that I need to sort in reverse order. reverse() seems to work for one of them, but not the other. I have toggled between sort() and reverse(). for one vector, the expected behavior is seen and the order reverses. For the other, there is no change in order.

This is very simple code, so it's hard to imagine what is going wrong.

Code:

vector<float> vec1, vec2;
vec1[0] = 14.1102; vec1[1] = 14.1145;
vec2[0] = 15.8508; vec2[1] = 26.0842;
sort( vec1.begin(), vec1.end() );
sort( vec2.begin(), vec2.end() );
cout << "vector 1 sort" << endl;
cout << vec1[0] << endl; cout << vec1[1] << endl;
cout << "vector 2 sort" << endl;
cout << vec2[0] << endl; cout << vec2[1] << endl;
cout << endl;
cout << endl;
reverse( vec1.begin(), vec1.end() );
reverse( vec2.begin(), vec2.end() );
cout << "vector 1 reverse" << endl;
cout << vec1[0] << endl; cout << vec1[1] << endl;
cout << "vector 2 sort" << endl;
cout << vec2[0] << endl; cout << vec2[1] << endl;
cout << endl;

Printout is,

Code:

vector 1 sort
14.1102
14.1145
vector 2 sort
15.8508
26.0842
vector 1 reverse
14.1102
14.1145
vector 2 reverse
26.0842
15.8508

You can see that the order of the first vector did not change. Am I right in suspecting that the numbers are too similar for what ever method reverse() uses to determine the difference between values?

If that is not the problem, I have no idea where to look. Suggestions would be appreciated.

LMHmedchem