使用next_permutation来排列类的向量 [英] Use next_permutation to permutate a vector of classes

查看:163
本文介绍了使用next_permutation来排列类的向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用std :: next_permutation()来排列我创建的类的向量的元素?

Is it possible to use std::next_permutation() to permutate the elements of a vector of a class i created?

next_permutation )工作?

How does the comparison parameter in next_permutation() work?

推荐答案


可以使用std :: next_permutation()我创建的类的向量?

Is it possible to use std::next_permutation() to permutate the elements of a vector of a class i created?

是!

 #include<iostream>
 #include<vector>
 #include<algorithm>

int main()
 {
      typedef std::vector<int> V; //<or_any_class>
      V v;

      for(int i=1;i<=5;++i)
        v.push_back(i*10);
      do{
            std::cout<<v[0]<<" "<<v[1]<<" "<<v[2]<<" "<<v[3]<<" "<<v[4]<<std::endl;;
        }

       while(std::next_permutation(v.begin(),v.end()));
 }




next_permutation

How does the comparison parameter in next_permutation() work?

可能有助于

这篇关于使用next_permutation来排列类的向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆