【发布时间】:2018-05-21 11:04:20
【问题描述】:
我正在尝试对数字向量进行排序并忽略某个数字,即将它留在原处。 This answer 实际上并没有离开它被发现的元素。
例如,如果我有以下
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;}));
将test 排序为1 3 4 5 6 8 9 11 -1。我搜索了几个小时,并修改了自定义比较器和使用std::partition,但我无法提出将test 向量分类为1 3 4 5 -1 6 8 9 11 的解决方案。
这实际上非常困难吗?
【问题讨论】:
标签: c++ algorithm sorting c++11 stdvector