1

Possible Duplicate:
combination and permutation in C++

Let's say I have a vector with the following elements: {1,2,3}. How can I traverse the vector in a pair-wise fashion. So the first iteration would be {1,2}, the second {1,3} and finally the third is {2, 3}.

For triplets there would be only one iteration: {1,2,3} in this case.

Are there algorithms in STL or boost to accomplish that?

Thanks, Christian

4

1 回答 1

4
for (int i = 0; i < vec.size() - 1; ++i)
    for (int j = i + 1; j < vec.size(); ++j)
        std::cout << '{' << vec[i] << ',' << vec[j] << '}';
于 2013-01-09T19:05:28.907 回答