


C++98:
不推荐 swap(v1, v2),这样是深拷贝,降低效率
推荐 v1.swap(v2)

C++11:
swap(v1, v2),使用的是移动构造、移动赋值
v1.swap(v2)
效果一样了




#include
#include
#include
using namespace std;
int main()
{
vector<int> v = {1, 3, 2};
sort(v.begin(), v.end());
do
{
for(auto e: v)
{
cout << e << " ";
}
cout << endl;
}while(next_permutation(v.begin(),v.end())); // 从升序开始
return 0;
}

#include
#include
#include
using namespace std;
int main()
{
vector<int> v = {1, 3, 2};
sort(v.begin(), v.end(), greater<int>());
do
{
for(auto e: v)
{
cout << e << " ";
}
cout << endl;
}while(prev_permutation (v.begin(),v.end())); // 从降序开始
return 0;
}


返回的是第一个 >= val 的起始位置


返回的是第一个 > val 的值
求并集:
(用 multiset 也可以

求交集:

求差集:
