struct stHelper
{
bool operator()(const char& a,const char& b)const
{
return a == ' ' && b == ' ';
}
};
bool isOdd(int x)
{
return x % 2 != 0;
}
int main()
{
//1.字符串去重 unique方法
string s = "a b c";
auto last = unique(s.begin(), s.end(), stHelper());
for (auto x : s)
{
cout << x << endl;
}
//2.数组奇数排在偶数前 partition
int arr[] = { 1,2,3,4,5,6 };
partition(arr, arr + 6, &isOdd);//输出153426
//stable_partition(arr,arr+6,&isOdd);
copy(arr, arr + 6, ostream_iterator<int>(cout, ","));
}
STL解决算法问题
于 2022-04-05 10:27:40 首次发布