I am trying to sort a vector of numbers and ignore a certain number, i.e. leave it in place. This answer does not actually leave the element where it was found.
For example if I have the following
std::vector<int> test{5, 3, 8, 4, -1, 1, 11, 9, 6};
std::sort(test.begin(),
std::partition(test.begin(), test.end(), [](int n)
{return n != -1;}));
Sorts test
into 1 3 4 5 6 8 9 11 -1
. I searched for a couple hours, and tinkered with both custom comparators and using std::partition
, but I cannot come up with a solution that sorts the test
vector into 1 3 4 5 -1 6 8 9 11
.
Is this just practically very difficult?