I have a vector containing positive integers and -1. My problem is that I want to sort the vector, but I don't touch -1 elements , just using std::sort (I know other approaches to solving it).
For instance:
Input: [-1, 150, 190, 170, -1, -1, 160, 180]
Output: [-1, 150, 160, 170, -1, -1, 180, 190]
It is my idea to solve it, but it did not work:
sort(myVector.begin(), myVector.end(), [&](const int& a,const int& b)->bool { if (a == -1 || b == -1) return &a < &b; return a < b; });
My way out: [-1, 150, 170, 190, -1, -1, 160, 180]
The output should be: [-1, 150, 160, 170, -1, -1, 180, 190]
Is there any idea to solve this problem with std::sort ?