template <class ForwardIterator, class UnaryPredicate>
ForwardIterator partition (ForwardIterator first,ForwardIterator last, UnaryPredicate pred)
{
while (true)
{
while (true)
if (first == last)//头指针等于尾指针,所有操作结束
return first;
else if (pred(*first))//头指针所指元素不符合移动条件
++first;
else//头指针所指元素符合移动条件,跳出内循环
break;
--last;//尾指针减1
while (true)
if (first == last)//头指针等于尾指针,所有操作结束
return first;
else if (!pred(*last))//尾指针所指元素不符合移动条件
--last;
else//尾指针所指元素符合移动条件,跳出内循环
break;
iter_swap(first, last);//头尾指针所指元素彼此交换
++first;//头指针前进1,准备下一个外循环迭代
}
}
template <class ForwardIterator, class UnaryPredicate>
ForwardIterator stable_partition (ForwardIterator first,ForwardIterator last, UnaryPredicate pred);