One more way to list combinations, in addition to 240114. Thee ways:
- no recursion: each loop adding one more letter to output set
- with recursion:
2a: each recursion add one more input letter: meCombinationEnumerationUtilRecursionInput
2b: each recursion grow the output length by one: meCombinationEnumerationUtilRecursionOutput
meCombinationEnumerationUtilRecursionOutputsPrefix, & sInput, iPrefixLen, set& output, iOutputLen, ) is for case 2b.
sInput is string, but it stands for a set of chars. no repeats in sInput-s
adds sInput to output, and grows the sInput length by one, from 0 to full length.
triggers all calls with this new sInput length
e.g. for 1234 here is the sInput-s as input:
first level: ""
second level: "1" "2" "3" "4"
third level:
when called from "1": "12" "13" "14"
when called from "2": "23" "24"
when called from "3": "34"
when called from "4": none
as seen at third level, when length == 2,
sInput never repeat the earlier ones by only appending chars after, controlled by iStart.
Output order is different comparing to 2a:
2a: output by input length. output is also input; later output depending in previous output to be complete.
function is caled the same number as the number of inputs, which is much smaller.
2b: output by output length. output never used as input
function is caled the same number as the combinations, which is much bigger.
for pumutation, the frame is very similar, the difference is just the candicates. e.g 1234
With prefix 1 candidates 234, we make new sPrefix 13 by swapping with 2 and 3, resulting in candicates are 24
then new sPrefix 14 by swapping with 2 and 4, resulting in candicates are 32
Download: http://riowing.net/p/wp/Combination.cpp