|
Re: Recursive permutation of string
So if you wanted to use the more 'standard' permute algorithm, as is the one I posted, but need the signature to be: void permute(char[] str, int low, int high). You will notice the address of "r" is not changing each recursion. All you need to do is make r a global variable or accessable by the class. That leaves you with the same format for the prototype: void permutate(char *s, int k, int n).
If your algorithm works, it may be more obfucated (or difficult to prove its correctness), but it's certainly more clever. I've never seen a permutation done by swapping characters repeatedly. Where did you get the idea from?
|