Click to See Complete Forum and Search --> : randomizing strings


threadhead
01-11-2003, 08:22 PM
hey.
my question is about programming in C.
lets assume that a user inputs the letters "abc".
now an algorithm should try out evey combination
that is possible with these three letters.
like: "abc", "cba", "bca", "bac", "acb", "cab".

how would i implement such a code?

help is appreciated (im really stuck with this ;))

truls
01-12-2003, 10:50 AM
This is what is called "permutation" of a string.

Do a search on google for "permutation algorithm" and you'll find plenty of help. You can also search on dejanews. If you were using C++ you could use the STL next_permutation algorithm.

threadhead
01-12-2003, 12:33 PM
i figured it out with a little help.

but thanks anyway. ;)