索引组合算法原型

// next_permutation example
#include <iostream>     // std::cout
#include <algorithm>    // std::next_permutation, std::sort

int make_combination(int myints[], int start , int end, int requirement_number){
    //std::cout<<"start:"<<start<<"end:"<<end<<"requirement_number:"<<requirement_number<<std::endl;
    if (start == end){
        std::cout << myints[start] << ",";
        requirement_number--;
        if (requirement_number >= 1){
            std::cout << "not ok" << std::endl;
            return 1;
        }else {
            std::cout << std::endl;
            return 0;
        }
    }
    if (1 ==requirement_number){
        requirement_number--;
        std::cout << myints[start] << std::endl;
        return 0;
    }
    std::cout<<myints[start];
    requirement_number--;
    return make_combination(myints, start+1, end, requirement_number );
}

int main () {
  int myints[] = {1,2,3};

  std::sort (myints,myints+3);
  int i =0;
  for(; i<3; i++){
    make_combination(myints, i, 2, 1);
  }

//  std::cout << "The 3! possible permutations with 3 elements:
";
//  do {
//    std::cout << myints[0] << ' ' << myints[1] << ' ' << myints[2] << '
';
//  } while ( std::prev_permutation(myints,myints+3) );
//
//  std::cout << "After loop: " << myints[0] << ' ' << myints[1] << ' ' << myints[2] << '
';

  return 0;
}

 有bug,比如 1,2,3

只能给出

1,2

2,3

但是看不到

1,3

MySQL限时解答,24小时内友哥专业解答
http://www.yougemysqldba.com
如有进一步需要请联系微信onesoft007
微博账号@友哥一指
原文地址:https://www.cnblogs.com/youge-OneSQL/p/9483578.html