Usage of this next_combination code

前端 未结 1 1558
花落未央
花落未央 2020-12-18 07:15

Currently I am trying to generate combinations from a vector that contains some integers. For now I want it to print out all of the combinations that are of length to_genera

相关标签:
1条回答
  • 2020-12-18 07:57

    The second template argument shouldn't be bool. You can allow compiller to handle types and simply write:

    while(next_combination(combo.begin(), combo.begin() + to_generate, combo.end(), std::less<int>()))
        for(std::vector<int>::iterator iter = combo.begin(); iter != combo.end() ; ++iter)
            std::cout << *iter << " ";
    

    And use spaces - it makes code look better.

    0 讨论(0)
提交回复
热议问题