类别: 算法 | 组件类型: 函数 |
template <class ForwardIterator, class Predicate> ForwardIterator stable_partition(ForwardIterator first, ForwardIterator last, Predicate pred);
stable_partition. 的返回值与partition不同,因为stable_partition保证保留相对顺序。也就是说,如果xiy是pred中的元素,并且pred(x) == pred(y), 并且如果xxy在stable_partitionyxxy. [1]
int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; const int N = sizeof(A)/sizeof(int); stable_partition(A, A + N, compose1(bind2nd(equal_to<int>(), 0), bind2nd(modulus<int>(), 2))); copy(A, A + N, ostream_iterator<int>(cout, " ")); // The output is "2 4 6 8 10 1 3 5 7 9". [1]
Nstable_partition中是线性的。无论哪种情况,partition都会被精确调用partition.