Howto create combinations of several vectors without hardcoding loops in C++?

前端 未结 10 988
慢半拍i
慢半拍i 2020-11-29 08:40

I have several data that looks like this:

Vector1_elements = T,C,A
Vector2_elements = C,G,A
Vector3_elements = C,G,T
..... up to ...
VectorK_elements = ...

         


        
10条回答
  •  隐瞒了意图╮
    2020-11-29 09:17

    The basic difficulty with recursion here is that you need to keep track of the entire list of indices (or else construct the string incrementally, as another question points out).

    An expedient way to handle this problem without constructing additional objects inside the loops is to hand your recursive function a vector of indices, of the same length as the vector of vectors:

    void printcombos(const vector >&vec,vector&index,int depth) {
      if(depth==index.length()) {
        for(int i=0; i &myvec= vec[depth];
        int mylength= myvec.length();
        for(int i=0; i

提交回复
热议问题