include/marathon/combination_generator.h
bool next() {

            /***********************************************************************************
             * Generate all combinations of k out of n items with Algorihtm L of TAoCP -
             * Combinatorial Algorithms Part I
             **********************************************************************************/

            j = 1;
            while (c[j] + 1 == c[j + 1]) {
                c[j] = j - 1;
                j++;
            }

            if (j > k)
                return false;

            c[j] = c[j] + 1;

            // generate output
            for (size_t i = 1; i <= k; i++)
                dst[i - 1] = src[c[i]];

            return true;

#ifdef false
            /***********************************************************************************
             * Generate all combinations of k out of n items with Algorihtm T of TAoCP -
             * Combinatorial Algorithms Part I
             **********************************************************************************/

            // j is the smallest index such that c[j+1] > j

            if (j > 0) {
                x = j;
                c[j] = x;                // increase c[j]
                j--;
            }
            else if (c[1] + 1 < c[2]) {   // easy case
                c[1]++;
            }
            else {                       // find j
                j = 1;
                do {
                    j++;
                    c[j - 1] = j - 2;
                    x = c[j] + 1;
                } while (x == c[j + 1]);

                if (j > k) {
                    return false;
                }
                else {                  // increase c[j]
                    c[j] = x;
                    j--;
                }
            }

            // generate output
            for (int i = 1; i <= k; i++)
                dst[i - 1] = src[c[i]];

            return true;
#endif
        }
/**
         * Generate the next combination.
         * @return True, if a new combination has been generated, false if all combination have been generated.
         */
Generate the next combination.
@return True, if a new combination has been generated, false if all combination have been generated.
Generate the next combination . @return True if a new combination has been generated false if all combination have been generated .
bool next() {
            j = 1;
            while (c[j] + 1 == c[j + 1]) {
                c[j] = j - 1;
                j++;
            }
            if (j > k)
                return false;
            c[j] = c[j] + 1;
            for (size_t i = 1; i <= k; i++)
                dst[i - 1] = src[c[i]];
            return true;
#ifdef false
            if (j > 0) {
                x = j;
                c[j] = x;                
                j--;
            }
            else if (c[1] + 1 < c[2]) {   
                c[1]++;
            }
            else {                       
                j = 1;
                do {
                    j++;
                    c[j - 1] = j - 2;
                    x = c[j] + 1;
                } while (x == c[j + 1]);
                if (j > k) {
                    return false;
                }
                else {                  
                    c[j] = x;
                    j--;
                }
            }
            for (int i = 1; i <= k; i++)
                dst[i - 1] = src[c[i]];
            return true;
#endif
        }
bool next ( ) { j = 1 ; while ( c [ j ] + 1 == c [ j + 1 ] ) { c [ j ] = j - 1 ; j ++ ; } if ( j > k ) return false ; c [ j ] = c [ j ] + 1 ; for ( size_t i = 1 ; i <= k ; i ++ ) dst [ i - 1 ] = src [ c [ i ] ] ; return true ; #ifdef false if ( j > 0 ) { x = j ; c [ j ] = x ; j -- ; } else if ( c [ 1 ] + 1 < c [ 2 ] ) { c [ 1 ] ++ ; } else { j = 1 ; do { j ++ ; c [ j - 1 ] = j - 2 ; x = c [ j ] + 1 ; } while ( x == c [ j + 1 ] ) ; if ( j > k ) { return false ; } else { c [ j ] = x ; j -- ; } } for ( int i = 1 ; i <= k ; i ++ ) dst [ i - 1 ] = src [ c [ i ] ] ; return true ; #endif }
Generate the next combination.
Generate the next combination .
/***********************************************************************************
             * Generate all combinations of k out of n items with Algorihtm L of TAoCP -
             * Combinatorial Algorithms Part I
             **********************************************************************************/ // generate output /***********************************************************************************
             * Generate all combinations of k out of n items with Algorihtm T of TAoCP -
             * Combinatorial Algorithms Part I
             **********************************************************************************/ // j is the smallest index such that c[j+1] > j // increase c[j] // easy case // find j // increase c[j] // generate output