To find all possible permutations of a given binary string (template), for example
Permutations of 1000 are 1000, 0100, 0010, 0001
void permutation(int no_ones, int no_zeroes, string accum){ if(no_ones == 0){ for(int i=0;i<no_zeroes;i++){ accum += "0"; } cout << accum << endl; return; } else if(no_zeroes == 0){ for(int j=0;j<no_ones;j++){ accum += "1"; } cout << accum << endl; return; } permutation (no_ones - 1, no_zeroes, accum + "1"); permutation (no_ones , no_zeroes - 1, accum + "0"); } int main(){ string append = "";
source share