C++ 算法库(3) 划分操作(二)

2014-11-24 08:21:32 · 作者: · 浏览: 1
me values:
for (int i=1; i<10; ++i) myvector.push_back(i); // 1 2 3 4 5 6 7 8 9

std::vector ::iterator bound;
bound = std::stable_partition (myvector.begin(), myvector.end(), IsOdd);

// print out content:
std::cout << "odd elements:";
for (std::vector ::iterator it=myvector.begin(); it!=bound; ++it)
std::cout << ' ' << *it;
std::cout << '\n';

std::cout << "even elements:";
for (std::vector ::iterator it=bound; it!=myvector.end(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';

return 0;
}

输出:

1
2
odd elements: 1 3 5 7 9
even elements: 2 4 6 8


特别说明:函数的中文释义来自:http://classfoo.cn/cpp/head/76573_319/,例子来自:http://www.cplusplus.com/reference/algorithm/