"luserXtrog" <(E-Mail Removed)> wrote in message

news:(E-Mail Removed)...

Alright. This would be easier in person with paper, but here goes.

The usual way to tackle this sort of thing is build up a sense

of the pattern involved. It's rather like constructing an inductive

proof; you start with the simplest example; then the next one;

then notice how the two differ and make a prediction about how

each case will differ from the previous; then you examine the third

example and check how it jives with the prediction. If your pattern

applies no matter how many cases you can produce (in a proof, this

is the inductive step), you're home free.

With permutations, you're likely to confuse yourself by not

sufficiently distinguishing between the set of source elements

(which here is a string) and the ordered selection that needs

to be generated (which also happens to be a string). On paper,

this can be made more clear by writing the source vertically

and constructing your permutations horizontally.

Example. Permute the single character 'a'.

source

a

permutations: a

Example. Permute the two characters 'a' and 'b'.

source

a

b

permutations: ab ba

With me so far?

Now you may not be able to fully enunciate the pattern at this

point. Keep going and something will have to click eventually.

Example. Permute the characters in "abc".

source

a

b

c

permutations:

abc acb

bac bca

cab cba

Now a pattern has emerged. The pattern was already present in

the way I (consciously or otherwise) chose to write these down.

I started by putting something in the leftmost slot and then

performing the 2-character permutation on the remaining slots

with the remaining elements.

I'd recommend you skip in-place manipulations for now.

Make a copy to use as the source set and make an empty

array to be filled in with characters selected from the

source. When you fill a slot erase the character from

the source. When the source is empty, your string should

be filled and you can blank out the string and refill

the source from the *real* source (which you've wisely

left unmodified for just this purpose). It'll mean

3 character arrays instead of just one, but if they're

named sensibly this should help you keep them straight.

Is this recursion the recursion dmr did his doctorate on? Or

mathematicall recursion? Anyway Is recursion what I need? I have found this.

http://publications.gbdirect.co.uk/c...t_passing.html