use*_*952 2 c++ stl permutation
鉴于此设定
set<string> s = {"a","b","c"};
Run Code Online (Sandbox Code Playgroud)
是否可以实现next_permutation()来获取所有组合,其中元素不重复和顺序重要?
不,这是不可能的. std::set是一个关联容器,并保持严格的弱排序. std::next_permutation转换给定的范围会破坏排序.
如果你需要获得set我建议你使用的内容的排列std::vector.您可以将集合复制到矢量中,然后从中获取排列.
std::set<int> set_data;
//fill set
std::vector<int> temp(set_data.begin(), set_data.end());
do
{
// code goes here
}
while(std::next_permutation(temp.begin(), temp.end()));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
325 次 |
| 最近记录: |